mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sql parser postgresql support
This commit is contained in:
+9
-1
@@ -638,7 +638,15 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
accept(Token.LPAREN);
|
||||
|
||||
for (; ; ) {
|
||||
SQLSelectOrderByItem item = this.exprParser.parseSelectOrderByItem();
|
||||
SQLSelectOrderByItem item;
|
||||
item = this.exprParser.parseSelectOrderByItem();
|
||||
|
||||
if (lexer.identifierEquals("jsonb_path_ops") && item.getExpr() instanceof SQLIdentifierExpr) {
|
||||
String ident = ((SQLIdentifierExpr) item.getExpr()).getName() + " " + lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
item.setExpr(new SQLIdentifierExpr(ident));
|
||||
}
|
||||
|
||||
item.setParent(stmt);
|
||||
stmt.addItem(item);
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
|
||||
@@ -70,6 +70,32 @@ public class PGCreateIndexTest_0 extends PGTest {
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
// System.out.println("fields : " + visitor.getColumns());
|
||||
|
||||
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("public.city")));
|
||||
//
|
||||
// assertTrue(visitor.getTables().get(new TableStat.Name("public.city")).getCreateIndexCount() == 1);
|
||||
//
|
||||
// assertEquals(1, visitor.getColumns().size() );
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
String sql = "create index if not exists idx_json_data_path on yida_entity_instance using gin(json_data jsonb_path_ops)";
|
||||
|
||||
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals("CREATE INDEX IF NOT EXISTS idx_json_data_path ON yida_entity_instance USING gin (json_data jsonb_path_ops)", SQLUtils.toPGString(stmt));
|
||||
|
||||
assertEquals("create index if not exists idx_json_data_path on yida_entity_instance using gin (json_data jsonb_path_ops)", stmt.toLowerCaseString());
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
// System.out.println("fields : " + visitor.getColumns());
|
||||
|
||||
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("public.city")));
|
||||
//
|
||||
// assertTrue(visitor.getTables().get(new TableStat.Name("public.city")).getCreateIndexCount() == 1);
|
||||
|
||||
Reference in New Issue
Block a user