use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement in project druid by alibaba.
the class PGSQLStatementParser method parseWith.
public SQLStatement parseWith() {
PGWithClause with = this.parseWithClause();
if (lexer.token() == Token.INSERT) {
PGInsertStatement stmt = this.parseInsert();
stmt.setWith(with);
return stmt;
}
if (lexer.token() == Token.SELECT) {
PGSelectStatement stmt = this.parseSelect();
stmt.setWith(with);
return stmt;
}
if (lexer.token() == Token.DELETE) {
PGDeleteStatement stmt = this.parseDeleteStatement();
stmt.setWith(with);
return stmt;
}
throw new ParserException("TODO");
}
use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement in project druid by alibaba.
the class PGSelectTest21 method test_1.
public void test_1() throws Exception {
String sql = "with a(a1,b1) as (select * from b) select * from a";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
assertTrue(statemen instanceof PGSelectStatement);
assertTrue(((PGSelectStatement) statemen).getWith().getWithQuery().size() == 1);
StringBuffer sb = new StringBuffer();
((PGSelectStatement) statemen).getWith().getWithQuery().get(0).getName().output(sb);
assertTrue("a".equals(sb.toString()));
assertTrue(((PGSelectStatement) statemen).getWith().getWithQuery().get(0).getColumns().size() == 2);
}
use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement in project druid by alibaba.
the class PGSelectTest1 method test_1.
public void test_1() throws Exception {
String sql = "(select * from a) union select * from b";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
assertTrue(statemen instanceof PGSelectStatement);
PGSelectStatement select = (PGSelectStatement) statemen;
assertTrue(select.getSelect().getQuery() instanceof SQLUnionQuery);
SQLUnionQuery unionQuery = (SQLUnionQuery) select.getSelect().getQuery();
assertTrue(unionQuery.getLeft() instanceof SQLSelectQueryBlock);
assertTrue(unionQuery.getRight() instanceof SQLSelectQueryBlock);
SQLSelectQueryBlock leftQueryBlock = (SQLSelectQueryBlock) unionQuery.getLeft();
assertTrue(leftQueryBlock.isParenthesized());
}
use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement in project druid by alibaba.
the class PGSQLStatementParser method parseSelect.
public PGSelectStatement parseSelect() {
PGSelectParser selectParser = createSQLSelectParser();
SQLSelect select = selectParser.select();
return new PGSelectStatement(select);
}
use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement in project druid by alibaba.
the class PGIntervalSQLTest method equal.
private void equal(String targetSql, String resultSql) {
PGSQLStatementParser parser = new PGSQLStatementParser(targetSql);
PGSelectStatement statement = parser.parseSelect();
Assert.assertTrue(statement.toString().equals(resultSql));
}
Aggregations