Skip to content

fix: preserve statement boundaries after PostgreSQL routines - #2650

Merged
manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:fix/postgres-routine-boundaries
Sep 20, 2026
Merged

manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:fix/postgres-routine-boundaries

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

PostgreSQL routines with AS '...' bodies can consume every following statement. For example, CREATE FUNCTION f() RETURNS integer AS 'SELECT 1;' LANGUAGE sql; SELECT 2; currently becomes one CreateFunction. Recognize the quoted body and stop at the declaration's terminating semicolon so the second statement receives its own AST.

Fixes #1994.

  • Share body-literal capture between CREATE FUNCTION and CREATE PROCEDURE, preserving ordinary, escape and dollar-quoted text plus trailing routine options.
  • Preserve the required newline between continued body strings when rendering the legacy declaration parts. Respect explicit E'...' escapes without enabling backslash escaping for ordinary strings.
  • Keep parameter defaults and aliases inside unquoted routine blocks from being mistaken for the routine body boundary.
  • Cover the issue's published function and qualified index example together with a following SELECT. PostgreSQL-specific syntax requires Dialect.POSTGRESQL.

The existing declaration-parts API remains in place. Routine bodies stay opaque: this does not validate PL/pgSQL source or expose its internal statements as an AST. The issue's abbreviated body is tested for preservation; executable PostgreSQL examples are checked separately.

Validation:

  • 35 new regression-test executions covering statement counts and types, body preservation, toString and statement deparser round trips, consecutive routines/DDL, EOF, malformed quoting, trailing parse errors and existing unquoted routine behavior.
  • Full Gradle check: 7,510 tests, no failures or errors, 25 skipped; grammar ambiguity, formatting and static checks passed.
  • Maven clean verify: 7,492 tests, no failures or errors, 25 skipped.
  • PostgreSQL 18.6: 22 valid routine examples executed as original SQL, toString output and visitor output (66 successful executions). The following statement ran in each case, and PostgreSQL's stored prosrc matched across all three forms.

Syntax references: CREATE FUNCTION, CREATE PROCEDURE, and string constants.

@manticore-projects

Copy link
Copy Markdown
Contributor

Please resolve conflicts.

@minleejae

Copy link
Copy Markdown
Contributor Author

@manticore-projects Thanks for flagging this!

Please resolve conflicts.

Merged the latest master and resolved the grammar conflict. This keeps master's dialect-specific escape-string handling while preserving the quoted routine body and following-statement boundaries.

The full Gradle check passes on Java 17: 7,764 tests, 0 failures/errors, 25 skipped, including the routine-boundary, PostgreSQL comment-literal, statement-list deparser, grammar ambiguity and static checks. GitHub reports no merge conflicts; CI is running on the updated head.

Commit: c52b59ad

@manticore-projects
manticore-projects merged commit 2fc6e3e into JSQLParser:master Sep 20, 2026
10 checks passed
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

Successfully merging this pull request may close these issues.

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

2 participants