Skip to content

DuckDB: support * RENAME, unparenthesized star modifiers and a trailing comma - #2801

Merged
manticore-projects merged 3 commits into
JSQLParser:masterfrom
guizmaii:duckdb-star-modifiers
Oct 13, 2026
Merged

manticore-projects merged 3 commits into
JSQLParser:masterfrom
guizmaii:duckdb-star-modifiers

Conversation

@guizmaii

@guizmaii guizmaii commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

For DuckDB's star expression modifiers (docs) and trailing commas in the select list (docs).

Input Before After
* RENAME (i AS x, j AS y), * RENAME i AS x error ColumnsTransformer of the new type RENAME
* EXCLUDE i, * EXCLUDE t.i error EXCLUDE with one column, printed without parentheses
* REPLACE i + 1 AS i error REPLACE with one item, printed without parentheses
SELECT a, b, FROM t, SELECT 1, LIMIT 1, (SELECT 1,) error the comma is dropped
  • ColumnsTransformer gains getRenameItems() and isParenthesized(). The unparenthesized forms are only recognised after * / t.*, as in DuckDB. REPLACE item needs an AS at its top level and RENAME needs column AS name for every column, so * rename / * replace stay aliases of the star and ClickHouse's REPLACE STRICT checks are unchanged.
  • Behaviour change: * REPLACE (a + 1) AS a is now DuckDB's single item (a + 1) AS a; it used to be an unaliased REPLACE(a + 1) with the star aliased a, which no dialect accepts.
  • The trailing comma is accepted before ), FROM, WHERE, HAVING, WINDOW, INTO, a set operator, GROUP BY/ORDER BY with an expression, and LIMIT/OFFSET followed by a number or ?. Columns and functions named after keywords keep parsing: SELECT a, limit FROM t, SELECT a, limit(1) FROM t, SELECT a, group by FROM t. A comma at the end of the input stays an error, and SELECT 1, LIMIT ALL is still a column. It applies wherever a select item list is parsed (RETURNING, PIVOT ... IN, DISTINCT ON, ...).
  • Apart from the REPLACE case above, all new inputs were errors in every dialect; on ~6,700 statements extracted from this repository's tests, results are identical to master.
  • checkGrammarAmbiguity: no conflicts. ./gradlew check: 10,118 tests, 0 failures.
  • DuckDB's own test suite (test/sql, 70,729 statements): 146 more parse, none less.

@guizmaii
guizmaii marked this pull request as ready for review October 13, 2026 09:19
Copilot AI balanced review requested due to automatic review settings October 13, 2026 09:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@guizmaii
guizmaii force-pushed the duckdb-star-modifiers branch 4 times, most recently from 12ff9c7 to a80100c Compare October 13, 2026 21:59
@manticore-projects

Copy link
Copy Markdown
Contributor

sorry, conflicts from overlapping PRs. Please resolve.

…ng comma

- `* RENAME (i AS x, j AS y)` and `* RENAME i AS x` are the new RENAME
  `ColumnsTransformer`.
- After `*`, `EXCLUDE i`, `REPLACE i + 1 AS i` and `RENAME i AS x` may
  name a single column or item without parentheses, and print back that
  way. Unparenthesized REPLACE and RENAME require the `AS name`.
- A select list may end with a comma before a clause such as FROM,
  WHERE or `ORDER BY`, or before `)`. Keywords that may name a column,
  as in `SELECT a, limit FROM t`, still do. The comma is not printed.
- Unparenthesized REPLACE needs an AS at the top level of its item, and
  RENAME needs `column AS name` for each item, so `* rename` and
  `* replace` stay aliases of the star.
- `REPLACE (a + 1) AS a` is a single item, as in DuckDB, not a list
  without an alias.
- A comma before `limit(` or `offset(` starts a select item again, and
  `group by` / `order by` right before FROM or the end are a column and
  its alias.
- A transformer with more than one item or column prints parentheses.
@guizmaii
guizmaii force-pushed the duckdb-star-modifiers branch from a80100c to 8353381 Compare October 13, 2026 22:25
@manticore-projects
manticore-projects merged commit f7d84c8 into JSQLParser:master Oct 13, 2026
4 of 5 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

@guizmaii

Copy link
Copy Markdown
Contributor Author

Rebased on master, conflicts resolved.

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.

3 participants