Sitelet https://github.com/stackql/stackql/pull/722
Skip to content

fix: [BUG] query rewriting error using JSON_EXTRACT - #722

Merged
general-kroll-4-life merged 1 commit into
stackql:mainfrom
Roshan931:prilog/fix-error-query-rewriter-rejects-non-column-08-21-2026-c60470
Aug 22, 2026
Merged

fix: [BUG] query rewriting error using JSON_EXTRACT#722
general-kroll-4-life merged 1 commit into
stackql:mainfrom
Roshan931:prilog/fix-error-query-rewriter-rejects-non-column-08-21-2026-c60470

Conversation

@Roshan931

Copy link
Copy Markdown
Contributor

Fixes #352

Root cause

Query rewriter rejects non-column projections over an indirection (subquery)

Changes

  • In internal/stackql/astvisit/query_rewriting.go the indirection branch of the AliasedExpr visit only tolerated an unresolvable column name when it looked like a json_each value or was an OrExpr (isAnonymous). Any other projected expression whose inferred name is not a column of the subquery (a function whose leading argument is a literal or a nested function, arithmetic, scalar subquery, ...) hard-failed. isAnonymous is replaced by isExpressionProjection, which treats every projection that is not a bare *sqlparser.ColName as opaque to the indirection's column inventory: the untyped relational column carrying the already-rendered decorated expression is emitted and passed to the SQL backend, exactly as the pre-existing json_each escape hatch does. Bare column references that do not exist in the subquery still error as before. Two robot scenarios were added to test/robot/functional/stackql_function_projection.robot (the json_extract-over-subquery case, sqlite-gated, and a backend-agnostic literal-leading function projection).

@general-kroll-4-life
general-kroll-4-life merged commit a5518b0 into stackql:main Aug 22, 2026
20 checks passed
@general-kroll-4-life

Copy link
Copy Markdown
Contributor

@Roshan931 thank you for your contribution

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.

[BUG] query rewriting error using JSON_EXTRACT

2 participants