You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parser::parse_create silently accepts and drops invalid modifiers across CREATE targets (e.g. CREATE TEMP POLICY) #3054
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:
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:
Only a few branches (USER MAPPING, FOREIGN TABLE, FOREIGN DATA WRAPPER, and the or_replace fallback) check if has_modifier.
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.
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.
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
Activity
[-]Refactor duplicated has_modifier guards in parse_create[/-][+]Refactor for LL(k)[/+][-]Refactor for LL(k)[/-][+]Parser::parse_create silently accepts and drops invalid modifiers across CREATE targets (e.g. CREATE TEMP POLICY) [/+]