Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg: Fix { $val: null } without $put: true #158

Merged
merged 11 commits into from
May 7, 2024
Merged

Conversation

aravindet
Copy link
Collaborator

Background:

Previously, this combination did not work (it would delete the property as if null was written, not { $val: null }). This behavior was inconsistent with Graffy semantics.

Changes:

The root cause of the bug was the use of the Postgres jsonb_strip_nulls() function, which recursively removed nulls; the behavior we wanted was a shallow version of this.

As no built-in function exists with the behavior we want, uses of jsonb_strip_nulls was replaced with the following subquery:

select jsonb_object_agg(key, value) from jsonb_each($object) where value <> 'null'::jsonb)

where $object is an expression returning a JSON object whose null properties are to be removed.

Additional changes to simplify the generated SQL:

  • skip the above null-stripping subquery where we are certain that the object cannot have any null properties
  • skip the pre-existing nullif() function (which converts an empty object to null), where we are certain that the object cannot be empty.

@aravindet aravindet merged commit 7e2c56a into next May 7, 2024
1 of 2 checks passed
@aravindet aravindet deleted the aravind/pg-val-null branch May 7, 2024 10:50
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.

2 participants