druid PGSQLStatementParser 不支持匿名代码块

q9rjltbz  于 2022-11-02  发布在  Druid
关注(0)|答案(5)|浏览(255)

PGSQLStatementParser不支持匿名代码块的解析,丢进去报错了。

执行如下代码

String sql = "DO $do$ BEGIN IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 't_myoperation') THEN\n"
          + "CREATE TABLE T_MYOPERATION (id BIGINT NOT NULL, creatorid BIGINT NOT NULL DEFAULT 0, orgid BIGINT NOT NULL DEFAULT 0, menuid CHARACTER VARYING (36) DEFAULT ' ', createtime TIMESTAMP WITHOUT TIME ZONE, bizid CHARACTER VARYING (36));\n"
          + "END IF; END $do$;";
      List<SQLStatement> sqlStatements = SQLUtils.parseStatements(sql, JdbcUtils.POSTGRESQL);
      String result= SQLUtils.toSQLString(sqlStatements, JdbcUtils.POSTGRESQL);
      System.out.println(result);

报错

Exception in thread "main" com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'DO $do$ BEGIN IF NOT EXISTS (S', expect DO, actual DO pos 2, line 1, column 1, token DO
	at com.alibaba.druid.sql.parser.SQLParser.printError(SQLParser.java:287)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:532)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:171)
	at com.alibaba.druid.sql.SQLUtils.parseStatements(SQLUtils.java:495)
	at com.alibaba.druid.MainTest.main(MainTest.java:14)

PGSQLStatementParser 能否提供下更多的支持,或者讨论下是否可以给你们提个pr也可以。

2o7dmzc5

2o7dmzc52#

确实是不支持

看PGSQLStatementParser 里面有好多todo exception,是否有计划实现一下代码?

ve7v8dk2

ve7v8dk23#

我来实现试试,有点难度

9w11ddsr

9w11ddsr4#

if 语句不支持啊,不好弄

r8uurelv

r8uurelv5#

if 语句不支持啊,不好弄

谢谢这位兄弟,我再自己想想办法

相关问题