Skip to content

Parser::parse_create silently accepts and drops invalid modifiers across CREATE targets (e.g. CREATE TEMP POLICY)  #3054

Backlog

Description

@lei-jia-xing

Describe the bug

sqlparser accepts invalid CREATE modifier combinations in PostgreSQL (and other dialects) and silently drops the modifier during AST construction / round-trip formatting.

Repro (test.sql):

CREATE TEMP POLICY p ON t USING (true);
 cargo run --quiet --example cli -- ./test.sql --postgres                                                                                              

Actual behavior:
Parsing succeeds and round-trips as:

CREATE POLICY p ON t USING (true)                                                                                                                     

TEMP is silently lost, even though PostgreSQL rejects CREATE TEMP POLICY as a syntax error (PostgreSQL CREATE POLICY docs
https://www.postgresql.org/docs/17/sql-createpolicy.html).

Root cause in Parser::parse_create

In src/parser/mod.rs, Parser::parse_create eagerly parses all CREATE prefix modifiers up front (or_replace, or_alter, multiset, local/global, transient, temporary, volatile, unlogged, persistent, create_view_params) and combines them into has_modifier before dispatching on the target object keyword.

However:

  1. Only a few branches (USER MAPPING, FOREIGN TABLE, FOREIGN DATA WRAPPER, and the or_replace fallback) check if has_modifier.
  2. Branches like Keyword::POLICY (parse_create_policy()) — as well as DOMAIN, INDEX, DATABASE, ROLE, TYPE, EXTENSION, RULE, AGGREGATE, COLLATION,OPERATOR, SERVER, VIRTUAL TABLE, TEXT SEARCH, and SNAPSHOT TABLE — neither accept temporary (or other flags) nor reject has_modifier.
  3. Even branches that take a subset of flags (e.g., parse_create_schema(or_replace), parse_create_sequence(temporary), parse_create_table(...)) silently ignore the remaining parsed flags (such as or_alter or transient on unsupported targets).

Because modifiers are parsed out of context before knowing the production, any branch that forgets to check or consume every flag silently corrupts the AST/round-trip.

Expected behavior / Suggested direction

• CREATE TEMP POLICY ... (and other unsupported combinations) should return a ParserError rather than silently dropping the modifier.
• Architecturally, instead of hoisting an unchecked bag of boolean flags in parse_create:
1. Either wrap parsed prefixes in a CreateModifiers struct whose fields must be exhaustively consumed/validated (rejecting any unconsumed modifier by default via a helper like modifiers.ensure_empty()), or
2. Look ahead to the object type (or parse object-specific modifiers inside each target production) instead of consuming arbitrary modifiers before dispatch.

Follow-up #3040

Activity

  1. changed the title [-]Refactor duplicated has_modifier guards in parse_create[/-] [+]Refactor for LL(k)[/+] on Nov 26, 2026
  2. changed the title [-]Refactor for LL(k)[/-] [+]Parser::parse_create silently accepts and drops invalid modifiers across CREATE targets (e.g. CREATE TEMP POLICY) [/+] on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions