Skip to content

Fix alias cloning for json recordset table-valued functions#3773

Merged
roji merged 1 commit intonpgsql:mainfrom
7645re:fix/json-groupby-alias
Mar 23, 2026
Merged

Fix alias cloning for json recordset table-valued functions#3773
roji merged 1 commit intonpgsql:mainfrom
7645re:fix/json-groupby-alias

Conversation

@7645re
Copy link
Copy Markdown
Contributor

@7645re 7645re commented Mar 10, 2026

Fix alias cloning for json[b]_to_recordset in
PgTableValuedFunctionExpression.Clone(...).

For TVFs without ColumnInfos such as unnest, the original
alias must be preserved. For jsonb_to_recordset, output
columns are explicitly named, so the cloned alias must be
applied instead.

This could previously cause execution-time failures such as
missing FROM-clause entry for table "o0".

Adds a regression test covering GroupBy over a query filtered
by a JSON collection predicate and projecting ordered group
elements.

Fixes #3790

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes alias handling when cloning PostgreSQL table-valued function (TVF) expressions used for JSON json[b]_to_recordset, preventing invalid SQL aliases that can surface as runtime failures (e.g. missing FROM-clause entries).

Changes:

  • Adjust PgTableValuedFunctionExpression.Clone(...) to preserve the original alias when there is no explicit column list, and to apply the cloned alias when explicit output columns exist.
  • Add a functional regression test covering a GroupBy over a JSON-collection predicate with projection of ordered group elements.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/EFCore.PG/Query/Expressions/Internal/PgTableValuedFunctionExpression.cs Fixes alias cloning behavior for JSON recordset TVFs to keep FROM references consistent.
test/EFCore.PG.FunctionalTests/Query/AdHocJsonQueryNpgsqlTest.cs Adds a regression scenario exercising JSON collection predicates combined with grouping and element projection.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Thanks for the fix.

Can you please change this PR to target main instead of hotfix/9.0.5? I can backport it later. You can do this by editing the PR to change the target branch, and then rebase it locally and force-push.

@7645re 7645re changed the base branch from hotfix/9.0.5 to main March 12, 2026 10:07
@7645re 7645re force-pushed the fix/json-groupby-alias branch from 9d7137e to 82ffa7e Compare March 12, 2026 11:03
@7645re 7645re requested a review from roji March 12, 2026 19:15
@7645re
Copy link
Copy Markdown
Contributor Author

7645re commented Mar 23, 2026

@roji everything seems to be done, are there any suggestions?

Copy link
Copy Markdown
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM! Thanks for your contribution! I'll go ahead and backport this to 10.0.x as well.

@roji roji enabled auto-merge (squash) March 23, 2026 12:13
@roji roji disabled auto-merge March 23, 2026 12:13
@roji roji enabled auto-merge (squash) March 23, 2026 12:14
@roji roji merged commit fd26075 into npgsql:main Mar 23, 2026
10 checks passed
roji pushed a commit that referenced this pull request Mar 23, 2026
@roji
Copy link
Copy Markdown
Member

roji commented Mar 23, 2026

Backported to 10.0.2 via 12a1aa8

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.

Incorrect alias for jsonb_to_recordset when cloning the SelectExpression (because of GroupBy)

3 participants