Skip to content

DuckDB: parse slices with omitted bounds or a step - #2794

Merged
manticore-projects merged 2 commits into
JSQLParser:masterfrom
guizmaii:duckdb-slices
Oct 13, 2026
Merged

manticore-projects merged 2 commits into
JSQLParser:masterfrom
guizmaii:duckdb-slices

Conversation

@guizmaii

@guizmaii guizmaii commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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:

Input Before After
l[2:3] JsonExpression 2 : 3 slice 2..3
l[:2] NumericBind :2 slice ..2
l[2:], l[:], l[-5:] parse error slice
l[1:5:2], l[1:-:2] (DuckDB step, - = end) wrong tree / error slice with step
  • A : 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]].
  • Behaviour changes inside a subscript: l[:name] / l[:1] are now slices up to name / 1, no longer a JDBC named parameter / numeric bind; Snowflake's l[v:i] is now a slice. Both follow PostgreSQL and DuckDB slice syntax.
  • RangeExpression (column subscripts) and ArrayExpression (other subscripts) gain a step and accept missing bounds. A missing stop before a step deparses as -, since l[1::2] would lex as a cast.
  • TablesNamesFinderTraversalTest asserted the JsonExpression parse of f()[1:2]; it now asserts the slice bounds.
  • checkGrammarAmbiguity: no conflicts. ./gradlew check: 10,121 tests, 0 failures.
  • DuckDB's own test suite (test/sql, 70,729 statements): 36 more parse, none less.

`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.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 07:56

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 marked this pull request as draft October 13, 2026 07:58
@guizmaii guizmaii changed the title Parse slices with omitted bounds or a step DuckDB: parse slices with omitted bounds or a step Oct 13, 2026
`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.
@guizmaii
guizmaii marked this pull request as ready for review October 13, 2026 08:06
@manticore-projects
manticore-projects merged commit aa9ecfe into JSQLParser:master Oct 13, 2026
10 checks passed
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