Handle nested parentheses in INSERT subquery detection#2387
Open
sabir-akhadov-localstack wants to merge 1 commit into
Open
Handle nested parentheses in INSERT subquery detection#2387sabir-akhadov-localstack wants to merge 1 commit into
sabir-akhadov-localstack wants to merge 1 commit into
Conversation
When parsing `INSERT INTO t <source>`, the parser must decide whether the tokens following the table name begin an explicit column list `(a, b, ...)` or the source query `(SELECT ...)`. `peek_subquery_start` made this decision by matching exactly `( SELECT`, so a source query wrapped in more than one layer of parentheses — e.g. `INSERT INTO t ((SELECT 1))` — was mistaken for a column list and failed to parse. Skip any number of leading `(` and treat the tokens as a subquery start as long as at least one paren precedes the `SELECT`. This matches how nested parentheses around subqueries are already handled elsewhere via recursive descent. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
6db7f86 to
d208e5e
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.
Before this change the statement above failed to parse: a source query wrapped in more than one layer of parentheses was mistaken for an INSERT column list.
When parsing
INSERT INTO t <source>, the parser must decide whether the tokens following the table name begin an explicit column list(a, b, ...)or the source query(SELECT ...). It made this decision inpeek_subquery_startby matching exactly( SELECT, so any extra leading paren tripped the column-list branch — even though the equivalent nested-parenthesized subquery parses fine in other positions.This changes
peek_subquery_startto skip any number of leading(and treat the tokens as a subquery start as long as at least one paren precedes theSELECT, making INSERT consistent with how nested parentheses around subqueries are already handled elsewhere via recursive descent.A regression test is added in
tests/sqlparser_common.rscoveringINSERT INTO t ((SELECT 1))andINSERT INTO t (((SELECT 1))).