Skip to content

Do not consume statement terminator in unparenthesized option lists - #2376

Merged
iffyio merged 2 commits into
apache:mainfrom
LucaCappelletti94:create-user-consumes-terminator
Jun 17, 2026
Merged

Do not consume statement terminator in unparenthesized option lists#2376
iffyio merged 2 commits into
apache:mainfrom
LucaCappelletti94:create-user-consumes-terminator

Conversation

@LucaCappelletti94

@LucaCappelletti94 LucaCappelletti94 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

CREATE USER <name> and ALTER USER <name> SET ... parse on their own, but CREATE USER user1; SELECT 1 (and the two ALTER USER ... SET forms) fail with Expected: end of statement, found: SELECT. The trailing option list is read by parse_key_value_options, whose loop drives on next_token() and breaks on a ; that it has already consumed. With the terminator gone, the top-level statement loop sees the next statement's first token directly and errors out. The bug is dialect independent and affects every unparenthesized caller of the helper: CREATE USER and both ALTER USER ... SET branches. Statements that never reach the helper (CREATE ROLE, DROP USER, ALTER USER ... RENAME) are unaffected, as are the parenthesized callers, which end on ).

This puts the semicolon back with prev_token() before breaking, so the caller and the top-level loop still see the separator, mirroring how the existing end-keyword arm already does it. The EOF arm needs no rewind. Fixing the single helper repairs all three statements at once. A regression test parses each of the three forms followed by SELECT 1 and asserts two statements result.

@LucaCappelletti94
LucaCappelletti94 force-pushed the create-user-consumes-terminator branch from a2faf7b to dabfe2b Compare June 11, 2026 14:21
@LucaCappelletti94 LucaCappelletti94 changed the title Do not consume statement terminator in CREATE USER option list Do not consume statement terminator in unparenthesized option lists Jun 11, 2026
Comment thread tests/sqlparser_common.rs Outdated
@LucaCappelletti94
LucaCappelletti94 force-pushed the create-user-consumes-terminator branch from dabfe2b to 81a6fb0 Compare June 16, 2026 13:41
@LucaCappelletti94
LucaCappelletti94 requested a review from iffyio June 16, 2026 14:25

@iffyio iffyio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @LucaCappelletti94!

@iffyio
iffyio added this pull request to the merge queue Jun 17, 2026
Merged via the queue into apache:main with commit 8cd2997 Jun 17, 2026
10 checks passed
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.

2 participants