Fix INSERT parser failing on double-parenthesized compound SELECT#98247
Merged
alexey-milovidov merged 1 commit intomasterfrom Feb 27, 2026
Merged
Fix INSERT parser failing on double-parenthesized compound SELECT#98247alexey-milovidov merged 1 commit intomasterfrom
alexey-milovidov merged 1 commit intomasterfrom
Conversation
When `ASTSelectWithUnionQuery::formatQueryImpl` formats a compound SELECT (e.g., with `INTERSECT`/`EXCEPT`) that is a child of INSERT, it wraps nested unions in parentheses for correctness. This can produce queries like `INSERT INTO t1 ((SELECT 1) EXCEPT ALL (SELECT 2)) INTERSECT (SELECT 3)`. The INSERT parser failed to re-parse such queries because when it encountered `((SELECT ...`, it consumed the first `(` for the column list check, then failed to parse `(` as a column name and returned false immediately, instead of rewinding and letting the `(` be parsed as part of a SELECT query. The fix rewinds `pos` to before the `(` when column list parsing fails entirely, matching the existing behavior when column parsing succeeds but no closing `)` is found. Closes #90925 https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=bfd26cd518682a2051429b51714e9c8c62806f45&name_0=MasterCI&name_1=BuzzHouse%20%28amd_debug%29&name_1=BuzzHouse%20%28amd_debug%29 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
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
INTERSECT/EXCEPToperatorsINSERT INTO t1 ((SELECT 1) EXCEPT ALL (SELECT 2))), the parser now correctly handles the double parenthesesThe root cause: the INSERT parser consumed the first
(for column list parsing, but when the second(couldn't be parsed as a column name, it returnedfalseinstead of rewindingposto try parsing((SELECT ...)as a compound SELECT query.Closes #90925
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=bfd26cd518682a2051429b51714e9c8c62806f45&name_0=MasterCI&name_1=BuzzHouse%20%28amd_debug%29&name_1=BuzzHouse%20%28amd_debug%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
🤖 Generated with Claude Code