Skip to content

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

Closed

Description

@kxed

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!

Activity

  1. manticore-projects commented on Apr 19, 2024

    @manticore-projects
    Contributor

    Greetings.

    Both statements get parsed and no error message is thrown.

    What exactly is the challenge please?

  2. kxed commented on Apr 19, 2024

    @kxed
    Author

    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
  3. kxed commented on Apr 19, 2024

    @kxed
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions