Repository navigation
DuckDB: parse slices with omitted bounds or a step - #2794
Merged
Merged
Conversation
`l[2:]`, `l[:]` and `l[-5:]` failed, `l[2:3]` parsed as the JSON path `2 : 3` and `l[:2]` as the numeric bind `:2`. Inside a subscript, a `:` now separates the bounds of a slice rather than starting a JSON path. Slices also take DuckDB's optional step, `l[1:5:2]`, where a `-` stop stands for the end of the list, `l[1:-:2]`. `RangeExpression` and `ArrayExpression` gain a step and accept missing bounds.
guizmaii
marked this pull request as draft
October 13, 2026 07:58
`l[(SELECT c:a FROM t)]`, `l[f(x, c:a)]` and `l[CASE WHEN c:a = 1 ...]` failed: the subscript depth disabled the JSON path operator in every expression nested in the subscript. Only a `:` at the subscript's own top level, outside brackets, braces, parentheses and CASE, now separates slice bounds.
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, whose lists and strings support slices with omitted bounds and a step (docs).
Inside a subscript,
:was read as the Snowflake JSON path operator, so slices did not parse as slices:l[2:3]JsonExpression2 : 3l[:2]NumericBind:2l[2:],l[:],l[-5:]l[1:5:2],l[1:-:2](DuckDB step,-= end):at the top level of a subscript (col[...],expr[...]), outside any brackets, braces, parentheses or CASE opened in it, separates slice bounds instead of starting a JSON path. JSON paths elsewhere are unchanged:c:a[1],l[(SELECT c:a FROM t)],l[f(c:a)],l[ARRAY[c:a]].l[:name]/l[:1]are now slices up toname/1, no longer a JDBC named parameter / numeric bind; Snowflake'sl[v:i]is now a slice. Both follow PostgreSQL and DuckDB slice syntax.RangeExpression(column subscripts) andArrayExpression(other subscripts) gain a step and accept missing bounds. A missing stop before a step deparses as-, sincel[1::2]would lex as a cast.TablesNamesFinderTraversalTestasserted theJsonExpressionparse off()[1:2]; it now asserts the slice bounds.checkGrammarAmbiguity: no conflicts../gradlew check: 10,121 tests, 0 failures.test/sql, 70,729 statements): 36 more parse, none less.