{{ message }}
Support parenthesized table joins in FROM clause#97650
Merged
Merged
Conversation
Standard SQL allows parentheses around joined table expressions: `SELECT * FROM (t1 CROSS JOIN t2)`. ClickHouse previously rejected this with a syntax error because `ParserSubquery` only accepted SELECT/EXPLAIN inside parentheses. The fix adds a fallback in `ParserTableExpression`: when all normal parse attempts fail and the position is at `(`, try to parse the content as `ParserTablesInSelectQuery`. If it contains a join (more than one table element), convert it to `SELECT * FROM <tables>` and wrap as a subquery. Single-table parenthesization `(t1)` is not matched to avoid ambiguity with expression parentheses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Member
Author
|
The AST fuzzer failure (Bad cast from
|
Member
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
Standard SQL allows parentheses around joined table expressions in FROM clauses:
ClickHouse previously rejected this with
SYNTAX_ERRORbecauseParserSubqueryonly accepted SELECT/EXPLAIN inside parentheses. This is valid syntax in PostgreSQL, MySQL, DuckDB, and SQLite.The fix adds a fallback in
ParserTableExpression: when all normal parse attempts fail (subquery, function, identifier) and the position is at(, try parsing the content asParserTablesInSelectQuery. If it contains a join (more than one table element), convert it toSELECT * FROM <tables>and wrap as a subquery. Single-table parenthesization(t1)is intentionally not matched to avoid ambiguity with expression parentheses.Test plan
tests/queries/0_stateless/03985_parenthesized_from_join.sqlcovering CROSS JOIN, INNER JOIN with ON, alias on the parenthesized expression, and nested usage(SELECT ...), ORDER BY with tuple parens, IN with subqueries, CREATE TABLE with ORDER BY all work correctlyORDER BY (col1, col2)in metadata load correctly (the initial approach of modifyingParserSubquerybroke this — fixed by only modifyingParserTableExpression)Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support parenthesized table join expressions in FROM clause, e.g.
SELECT * FROM (t1 CROSS JOIN t2).🤖 Generated with Claude Code
Version info
26.3.1.93