Support CREATE SEQUENCE options in any order#2043
Closed
stevenliebregt wants to merge 1 commit into
Closed
Conversation
iffyio
reviewed
Sep 25, 2025
Comment on lines
+313
to
+320
| let sql9 = "CREATE SEQUENCE name6 | ||
| AS INTEGER | ||
| START WITH 1 | ||
| INCREMENT BY 1 | ||
| NO MINVALUE | ||
| NO MAXVALUE | ||
| CACHE 1"; | ||
| pg().one_statement_parses_to(sql9, "CREATE SEQUENCE name6 AS INTEGER START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1"); |
Contributor
There was a problem hiding this comment.
Suggested change
| let sql9 = "CREATE SEQUENCE name6 | |
| AS INTEGER | |
| START WITH 1 | |
| INCREMENT BY 1 | |
| NO MINVALUE | |
| NO MAXVALUE | |
| CACHE 1"; | |
| pg().one_statement_parses_to(sql9, "CREATE SEQUENCE name6 AS INTEGER START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1"); | |
| pg().verified_stmt("CREATE SEQUENCE name6 AS INTEGER START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1"); |
it looks like this should be equivalent?
Comment on lines
+17031
to
+17032
| let mut should_continue_loop = true; | ||
| while should_continue_loop { |
Contributor
There was a problem hiding this comment.
Suggested change
| let mut should_continue_loop = true; | |
| while should_continue_loop { | |
| loop { |
It looks like we can skip the bool var and instead use a combination of continue and break to manage the loop?
| Err(ParserError::ParserError(_)) | ||
| )); | ||
|
|
||
| let sql9 = "CREATE SEQUENCE name6 |
Contributor
There was a problem hiding this comment.
Can we add a test case with duplicate options?
Author
|
@iffyio thanks for the review, I'll be unable to address the comments for the next 2 weeks, but after that I'll address them |
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
amaksimo
added a commit
to amaksimo/datafusion-sqlparser-rs
that referenced
this pull request
Jun 5, 2026
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.
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.
This changes the parsing of the
CREATE SEQUENCEoptions to allow the individual options to appear in any order.The reason I'm opening this pull request is that the Postgres
pg_dumputility dumpsCREATE SEQUENCEstatements like this:Where the
START WITH 1appears before theINCREMENT BY 1, Postgres allows this but the parser did not.There should not be any noticable performance impact I think. I did run the benchmarks and did not see any impact.