GeezerVison is showing github.com — DuckDB: support list comprehensions by guizmaii · Pull Request #2798 · JSQLParser/JSqlParser
Conversation
guizmaii
commented
Oct 13, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
For DuckDB's list comprehensions (docs):
SELECT [x * 2 FOR x IN l IF x > 1], [x + i FOR x, i IN l] FROM t
- New
ListComprehension expression: element expression, one or two variables (element, 1-based index), list expression, optional IF condition.
- A
[ opens a comprehension only when FOR follows at its top level (isListComprehensionAhead(), one pass over the token chain; a 20,000-element array parses as fast as on master); every other [ is still an ArrayConstructor. [... FOR ...] was a syntax error in every dialect, so nothing that parsed before changes. SQL Server's [name] quoting is lexed before this and unaffected.
ExpressionVisitor.visit(ListComprehension) is a default method visiting the element, list and condition, so existing visitors keep compiling. The deparser, adapter, validator and TablesNamesFinder implement it (tables in a sub-select list are found).
checkGrammarAmbiguity: no conflicts. ./gradlew check: 10,120 tests, 0 failures.
- DuckDB's own test suite (
test/sql, 70,729 statements): 91 more parse, none less.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
`[x * 2 FOR x IN l IF x > 1]` and `[x + i FOR x, i IN l]` parse as the
new `ListComprehension`. A `[` opens one when a `FOR` follows at its top
level; any other `[` is still an array. `visit(ListComprehension)` is a
default method that visits the element, list and condition, so existing
`ExpressionVisitor` implementations keep compiling.
`isListComprehensionAhead()` called `getToken(i)` for each token, which
walks from the current token every time: parsing a 10,000-element array
took seconds. It now follows the token chain.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|