Skip to content

PostgreSQL: accept CREATE SEQUENCE options in any clause order#2367

Open
amaksimo wants to merge 1 commit into
apache:mainfrom
amaksimo:upstream/create-sequence-order
Open

PostgreSQL: accept CREATE SEQUENCE options in any clause order#2367
amaksimo wants to merge 1 commit into
apache:mainfrom
amaksimo:upstream/create-sequence-order

Conversation

@amaksimo
Copy link
Copy Markdown
Contributor

@amaksimo amaksimo commented Jun 5, 2026

Summary

PostgreSQL allows the CREATE SEQUENCE option 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:

CREATE SEQUENCE public.t_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

Changes

  • Wrap the option-matching arms of parse_create_sequence_options in a loop that breaks only when no clause matches. The AST vector preserves source order.
  • Doc-comment note on Statement::CreateSequence pointing at the PG docs.

Tests in tests/sqlparser_common.rs (PG-standard syntax also accepted by GenericDialect): pg_dump-shaped input parses to canonical form, two reorderings round-trip with order preserved, repeated-clause case pinned as characterization, and the original INCREMENT-first ordering still round-trips.

cargo test --all-features, cargo fmt --all, cargo clippy --all-targets --all-features -- -D warnings pass locally.

History

Re-pitch of #2043 (closed by stale-bot after the author was unavailable). Addresses 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.

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.
@amaksimo amaksimo force-pushed the upstream/create-sequence-order branch from 43bcd9b to f641be8 Compare June 5, 2026 23:30
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.

1 participant