Skip to content

Treat a JSON array element as nullable when setting a JSON property from it - #4136

Open
efeesrefinal wants to merge 1 commit into
npgsql:mainfrom
efeesrefinal:fix/json-set-out-of-range-element
Open

efeesrefinal wants to merge 1 commit into
npgsql:mainfrom
efeesrefinal:fix/json-set-out-of-range-element

Conversation

@efeesrefinal

Copy link
Copy Markdown
Contributor

Fixes #4097

ExecuteUpdate uses jsonb_set instead of jsonb_set_lax when the value cannot be NULL. A JSON array element was judged by the nullability of its element type, but an out-of-range index yields NULL whatever that type is, so jsonb_set received NULL and returned NULL for the whole document.

MayReturnNull now returns true for a JsonScalarExpression whose path contains an array index. The property becomes a JSON null and the rest of the document is kept. Before PostgreSQL 16 the same check adds the existing COALESCE to a JSON null; I only ran this against PostgreSQL 18, so that path is untested.

The new test Update_property_to_out_of_range_primitive_collection_element fails on main with a not-null violation (23502). The *BulkUpdate* and *Json* test classes pass against PostgreSQL 18.

This branch has not been deployed

No deployments
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.

ExecuteUpdate copying an out-of-range JSON array element sets the whole JSON column to NULL

1 participant