JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

[BUG] JSQLParser 4.9 fails to parse subsequent statements after parsing FUNCTION statement

Open kxed opened this issue 1 year ago • 3 comments

hi there!

I am using the JSQLParser4.9 tool to parse SQL DDL statements, but I encountered a problem when parsing the following statement:

SQL Example:

  • Simplified Query Example, focusing on the failing feature
    -- Replace with your ACTUAL example
    DROP FUNCTION IF EXISTS "fin"."restore_fund_data"("in_fund_id" int8);
    CREATE OR REPLACE FUNCTION "fin"."restore_fund_data"("in_fund_id" int8)
    RETURNS "pg_catalog"."varchar" AS $BODY$
    DECLARE
     message VARCHAR;
     open rec_cur;
     close proj_info_cur;
     ********
     RETURN 'success';
    END $BODY$
    LANGUAGE plpgsql VOLATILE
    COST 100;
    

Software Information:

  • JSqlParser 4.9 and 4.8
  • Database PostgreSQL

Thank you very much!

kxed avatar Apr 19 '24 04:04 kxed

Greetings.

Both statements get parsed and no error message is thrown.

What exactly is the challenge please?

manticore-projects avatar Apr 19 '24 04:04 manticore-projects

The "INDEX" keyword also failed to convert.

CREATE INDEX "index_keyword" ON "inter"."inter_ti_rec" USING btree (
  "keyword" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

Software Information:

  • JSqlParser 4.9 and 4.8
  • Database PostgreSQL

kxed avatar Apr 19 '24 04:04 kxed

Greetings.

Both statements get parsed and no error message is thrown.

What exactly is the challenge please?

Executing the following code will throw an exception.

try {
            Statements statements = CCJSqlParserUtil.parseStatements(sql);
            return statements;
        } catch (JSQLParserException e) {
            log.error(e.getMessage());
            throw new RuntimeException("Failed to parse the Sql file, please check if the Sql file is correct.");
        }

Exception Info:

c.s.g.util.sqlparse.BaseSqlParser : net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "end" "END" at line 2259, column 2.

Was expecting one of:

"("
"ALTER"
"ANALYZE"
"BEGIN"
"CALL"
"COMMENT"
"COMMIT"
"CREATE"
"DECLARE"
"DELETE"
"DESC"
"DESCRIBE"
"DROP"
"EXEC"
"EXECUTE"
"EXPLAIN"
"GRANT"
"IF"
"INSERT"
"MERGE"
"PURGE"
"REFRESH"
"RENAME"
"REPLACE"
"RESET"
"ROLLBACK"
"SAVEPOINT"
"SET"
"SHOW"
"TABLE"
"TRUNCATE"
"UPDATE"
"UPSERT"
"USE"
"VALUE"
"VALUES"
"WITH"
<EOF>
<K_SELECT>
<ST_SEMICOLON>

kxed avatar Apr 19 '24 05:04 kxed