Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kxed opened this issue Apr 19, 2024 · 3 comments

Comments

@kxed
Copy link

kxed commented Apr 19, 2024

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!

@manticore-projects
Copy link
Contributor

Greetings.

Both statements get parsed and no error message is thrown.

What exactly is the challenge please?

@kxed
Copy link
Author

kxed commented Apr 19, 2024

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
Copy link
Author

kxed commented Apr 19, 2024

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants