Repository navigation
DuckDB: accept FROM-first queries and TABLE t as subqueries and set operands - #2799
Merged
manticore-projects merged 2 commits intoOct 13, 2026
Merged
Conversation
…perands - `(FROM t ...)` is a sub-select wherever `(SELECT ...)` is, and a parenthesized `FROM t` without pipe operators is a FROM-first select. - FROM-first queries and `TABLE t` are set operation operands, e.g. `FROM a UNION ALL FROM b` or `TABLE a EXCEPT TABLE b`, with a trailing ORDER BY/LIMIT applying to the whole operation. - `WITH ... TABLE t` keeps and prints its WITH clause. - The FROM-first scan follows the token chain and stops at the end of the enclosing parentheses.
- `(TABLE` starts a sub-select only when a table name follows and then the end of the query, so `(table = 'hits')` and `(table)` stay expressions on a column named table. `FROM (TABLE s.t) x` now parses. - A parenthesized `FROM t` without clauses stays a `FromQuery`. - `TableStatement` uses `Select.appendTo`, and its deparser prints OPTION, FETCH and the isolation level, so `TABLE t FETCH FIRST 1 ROWS ONLY` keeps its FETCH. - `CREATE TABLE ... AS` takes any query, including `TABLE a UNION TABLE b`.
guizmaii
marked this pull request as ready for review
October 13, 2026 09:12
27 tasks
Contributor
|
Thank you! |
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.
For DuckDB, where FROM-first queries (docs) and
TABLE tare queries like any other:SELECT * FROM (FROM t),a IN (FROM u),(FROM u SELECT max(a))FROM a UNION ALL FROM b,SELECT 1 EXCEPT FROM b WHERE xSetOperationListof FROM-firstPlainSelectsTABLE a UNION TABLE b ORDER BY 1,(TABLE a EXCEPT ALL TABLE b)SetOperationListofTableStatements, ORDER BY on the listWITH t AS (SELECT 1) TABLE tTableStatementwith its WITH items, deparsedisParenthesedSelectAhead()/isParenthesedFromItemAhead()accept(FROM, and(TABLEwhen a table name follows and then), a set operator, ORDER, LIMIT, OFFSET or FETCH. So(table = 'hits'),(table)and(table.a)stay expressions on a column namedtable(ClickHouse'ssystem.parts), and Oracle'sTABLE(...)is untouched.Select(), FROM-first selects andTableStatementjoin the alternatives that can be followed by a set operation;SetOperationListaccepts them as operands and hoists a trailing ORDER BY/LIMIT/OFFSET from a lastTableStatementas it does for aPlainSelect. The separateTableStatement()statement alternative is now covered bySelect().isFromFirstSelectAhead()also recognises a following set operator, stops at the end of the enclosing parentheses, and follows the token chain instead of callinggetToken(i)per token. A bareFROM t, also parenthesized, and pipe queries are stillFromQuery.TableStatementusesSelect.appendTo, andTableStatementDeParserprints the WITH clause, OPTION, FETCH and the isolation level.CREATE TABLE ... AStakes any query, e.g.TABLE a UNION TABLE b;FROM (TABLE s.t) xnow parses.checkGrammarAmbiguity: no conflicts../gradlew check: 10,116 tests, 0 failures.test/sql, 70,729 statements): 155 more parse, none less.