Skip to content

fix: return UnsupportedStatement for CREATE forms that no rule models - #2864

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/unknown-create-fallback-20261027
Oct 28, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/unknown-create-fallback-20261027

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

CREATE falls back to UnsupportedStatement for forms it does not model, but only when no earlier alternative claims the statement. CREATE TABLE and CREATE INDEX accept any leading words as modifiers, so PostgreSQL statements such as CREATE LANGUAGE plperl, CREATE OPERATOR CLASS …, CREATE DEFAULT CONVERSION … or CREATE TRANSFORM … entered one of them and failed before reaching the fallback. With parseStatements, one such statement made the whole script fail. Forms whose object keyword is a reserved token, such as CREATE AGGREGATE or CREATE CAST, already fell back.

Create() now takes the fallback first when the statement contains none of TABLE, INDEX, VIEW and POLICY, which every remaining alternative needs. Statements that parse today keep their result. The fallback also keeps OR REPLACE, which Create() reads before choosing an alternative; CREATE OR REPLACE AGGREGATE … used to render without it.

Statements that failed this way now return UnsupportedStatement instead of throwing, as other unmodelled CREATE forms do. One existing test changes for this reason: CREATE DEFINER = x EVENT …, whose DEFINER the EVENT rule does not read yet, now falls back instead of failing. Public method signatures are retained.

Syntax reference: PostgreSQL 18 SQL commands.

Validation:

  • UnsupportedStatementTest adds 7 PostgreSQL CREATE forms, parsed with and without the PostgreSQL dialect, and a script in which CREATE LANGUAGE sits between CREATE TABLE and CREATE INDEX. All 8 fail on master 5d07ba424.
  • Java 17 Gradle check: 12,225 tests, 0 failures, 25 skipped; grammar ambiguity, formatting (Spotless ratchet against upstream/master), Checkstyle, PMD, SpotBugs and JaCoCo pass. JaCoCo instrumentation headroom of CCJSqlParser: 967 entries on master, 932 with this change.

AI assistance: prepared with Claude Code.

CREATE falls back to UnsupportedStatement only when no earlier
alternative claims the statement. CREATE TABLE and CREATE INDEX accept
any leading words as modifiers, so PostgreSQL statements such as CREATE
LANGUAGE, CREATE OPERATOR CLASS, CREATE DEFAULT CONVERSION or CREATE
TRANSFORM entered one of them and failed before the fallback, and
parseStatements failed for the whole script.

Take the fallback first when the statement contains none of TABLE,
INDEX, VIEW and POLICY, which every remaining alternative needs, so
statements that parse today keep their result. The fallback also keeps
OR REPLACE, which Create() reads before choosing an alternative.

Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects
manticore-projects merged commit b392e4a into JSQLParser:master Oct 28, 2026
4 of 5 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Good one!!! Especially those DDLs come in all kind a variations vendor lock-ins, so having strong fallback is most welcome here.

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.

2 participants