Skip to content

Generic: Reject unsupported prefix modifiers across CREATE statements - #3063

Open
lei-jia-xing wants to merge 1 commit into
apache:mainfrom
lei-jia-xing:parse-create-modifiers
Open

lei-jia-xing wants to merge 1 commit into
apache:mainfrom
lei-jia-xing:parse-create-modifiers

Conversation

@lei-jia-xing

Copy link
Copy Markdown

Closes #3054. Follow-up to #3040.

Previously, Parser::parse_create parsed prefix modifiers upfront and only checked has_modifier in three arms (USER MAPPING, FOREIGN TABLE,FOREIGN DATA WRAPPER), so other targets silently dropped unsupported modifiers (e.g. CREATE TEMP POLICY p ON t USING (true); round-tripped as CREATE POLICY p ON t USING (true), which PostgreSQL rejects per https://www.postgresql.org/docs/17/sql-createpolicy.html).

This PR replaces has_modifier with CreateModifiers::ensure_empty(target):

  • Each CREATE branch consumes only the modifiers its AST preserves and rejects any remaining modifier with "<TARGET> does not accept this modifier" at that modifier's location.
  • Dialect::supports_create_or_alter_function (enabled on MsSqlDialect) ensures non-MSSQL FUNCTION branches reject OR ALTER instead of dropping it.
  • LOCAL/GLOBAL are parsed once via parse_one_of_keywords so CREATE LOCAL GLOBAL TABLE fails instead of dropping LOCAL.

Note for reviewers on error message unification:

  • Parsing UNLOGGED uniformly alongside other modifiers replaces the pre-has_modifier peek_keywords(&[UNLOGGED, TABLE]) workaround from PostgreSQL UNLOGGED Table Support and ALTER TABLE ... SET LOGGED|UNLOGGED #2251, so CREATE UNLOGGED VIEW now reports "CREATE VIEW does not accept this modifier" instead of "Expected: an object type after CREATE, found: UNLOGGED".
  • Removing the mid-dispatch else if or_replace arm unifies OR REPLACE rejections on targets like FOREIGN TABLE to "CREATE FOREIGN TABLE does not accept this modifier" (matching USER MAPPING), and unknown targets after OR REPLACE to "Expected: an object type after CREATE".

AI assistance was used to implement the refactor and tests.

@lei-jia-xing
lei-jia-xing force-pushed the parse-create-modifiers branch from cd4dadc to 291585e Compare November 29, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant