PostgreSQL: accept CREATE SEQUENCE options in any clause order#2367
Open
amaksimo wants to merge 1 commit into
Open
PostgreSQL: accept CREATE SEQUENCE options in any clause order#2367amaksimo wants to merge 1 commit into
amaksimo wants to merge 1 commit into
Conversation
PostgreSQL allows the CREATE SEQUENCE option clauses (INCREMENT, MINVALUE, MAXVALUE, START, CACHE, CYCLE) to appear in any order. See https://www.postgresql.org/docs/current/sql-createsequence.html. The previous parser was positional and rejected pg_dump output, which emits START before INCREMENT: CREATE SEQUENCE public.t_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; Wraps the option-matching arms of `parse_create_sequence_options` in a loop that breaks out only when no clause matches the next token, so the AST vector preserves whatever order the source used. No performance impact; the inner work per clause is unchanged. Tests live in tests/sqlparser_common.rs since the syntax is plain PostgreSQL also accepted by GenericDialect: a pg_dump-shaped input parses to its canonical form, two reorderings of the same clauses both round-trip with order preserved, and the duplicate-clause case is pinned (current permissive behavior, characterization not contract). Re-pitch of apache#2043 (closed by stale-bot after author was unavailable) addressing the review feedback there: pure `else if ... else break` loop without a bool sentinel, `verified_stmt` round-trip tests in common, and a duplicate-clause test case.
43bcd9b to
f641be8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PostgreSQL allows the
CREATE SEQUENCEoption clauses (INCREMENT,MINVALUE,MAXVALUE,START,CACHE,CYCLE) to appear in any order, per the docs. The previous parser was positional and rejected pg_dump output:Changes
parse_create_sequence_optionsin a loop that breaks only when no clause matches. The AST vector preserves source order.Statement::CreateSequencepointing at the PG docs.Tests in
tests/sqlparser_common.rs(PG-standard syntax also accepted byGenericDialect): pg_dump-shaped input parses to canonical form, two reorderings round-trip with order preserved, repeated-clause case pinned as characterization, and the originalINCREMENT-first ordering still round-trips.cargo test --all-features,cargo fmt --all,cargo clippy --all-targets --all-features -- -D warningspass locally.History
Re-pitch of #2043 (closed by stale-bot after the author was unavailable). Addresses the review feedback there: pure
else if … else breakloop without a bool sentinel,verified_stmtround-trip tests in common, and a duplicate-clause test case.