Skip to content

Resolve TableCall names as functions and preserve nested json_each args#5696

Draft
kumarUjjawal wants to merge 2 commits intotursodatabase:mainfrom
kumarUjjawal:fix/join_each_empty_result
Draft

Resolve TableCall names as functions and preserve nested json_each args#5696
kumarUjjawal wants to merge 2 commits intotursodatabase:mainfrom
kumarUjjawal:fix/join_each_empty_result

Conversation

@kumarUjjawal
Copy link
Contributor

Description

This PR fixes incorrect TableCall resolution in the planner that caused nested table-valued function calls (notably json_each) to lose their arguments in subqueries.

Changes made:

  • Updated planner resolution so SelectTable::TableCall is treated as a function call path, not as a normal table/CTE reference path.
  • Added explicit parse-time error for non-callable targets when used as name(...): '<name>' is not a function, matching SQLite behavior.
  • Kept existing CTE/table shadowing behavior for normal table references (FROM cte) unchanged.
  • Added regression tests

Motivation and context

Issue #5157 reported SQLite compatibility breakage where nested json_each returned empty results after another json_each had executed.

Closes #5157

Description of AI Usage

Copy link

@turso-bot turso-bot bot left a comment

Choose a reason for hiding this comment

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

Please review @sivukhin

Copy link
Collaborator

@sivukhin sivukhin left a comment

Choose a reason for hiding this comment

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

@jussisaurio , what do you think if we will have separate translation methods for TableCall case? Seems like it is pretty special case and instead of rejecting all things handled in the generic parse_table method we can just implement small parse_table_call method instead.

@kumarUjjawal kumarUjjawal marked this pull request as draft March 18, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

json_each Returns Empty Result in Nested Subqueries

2 participants