Fix a bug where the result of a function that returns an array is not able to be accessed by array index.#3720
Merged
roji merged 2 commits intonpgsql:mainfrom Feb 7, 2026
Merged
Conversation
… able to be accessed by array index.
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where array indexing could not be applied to the result of a function that returns an array. The issue occurred because the Npgsql EF Core provider did not properly translate array indexing operations on expressions (like function results) and did not wrap function expressions in parentheses when applying array indexing.
Changes:
- Added support for translating array indexing on any expression with
NpgsqlArrayTypeMapping - Added logic to wrap function expressions in parentheses when used with array indexing
- Added test to verify array indexing on function results works correctly
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/EFCore.PG.FunctionalTests/Query/NorthwindDbFunctionsQueryNpgsqlTest.cs | Adds test case StringToArray_with_index() to verify array indexing on function results produces correct SQL with parentheses |
| src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs | Adds requirement for parentheses around SqlFunctionExpression when used as inner expression of array indexing |
| src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlArrayMethodTranslator.cs | Adds translation of ElementAt on expressions with NpgsqlArrayTypeMapping to PostgreSQL array index syntax |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
roji
approved these changes
Feb 7, 2026
Member
roji
left a comment
There was a problem hiding this comment.
Thanks! Pushed some tweaks and will merge and backport for 10.0.
Member
|
Backported to 10.0.1 via 253d4ae |
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.
Fix a bug where the result of a function that returns an array is not able to be accessed by array index.
This allows array indexing to be used on the result of an expression, not just a column. For example:
There were two problems that needed to be fixed:
NpgsqlArrayTypeMappingwas not being translated into an array index expression.Fixes #3383