Re: '{"x": 42, "y": null}'::jsonb != '{"x": 42}'::jsonb ... Really?

From: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
To: Thomas Kellerer <shammat(at)gmx(dot)net>
Cc: pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: '{"x": 42, "y": null}'::jsonb != '{"x": 42}'::jsonb ... Really?
Date: 2022-06-20 02:45:09
Message-ID: 7E6C88FF-F2FB-4C19-89CF-686E919AC1F7@yugabyte.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> shammat(at)gmx(dot)net wrote:
>
>> bryn(at)yugabyte(dot)com wrote:
>>
>> Am I missing a use case where an object with a key-value pair with a JSON null value is meaningfully different from one where the key is simply absent?
>
> It seems the JSON specification doesn't actually define equality. But the JSON patch RFC 6902:
>
> www.rfc-editor.org/rfc/rfc6902#section-4.6
>
> defines the equality of two objects as:
>
> «
> objects: are considered equal if they contain the same number of members, and if each member can be considered equal to a member in the other object, by comparing their keys (as strings) and their values (using this list of type-specific rules)
> »
>
> As {"x": 42, "y": null} and {"x": 42} do not contain the same number of members, I think Postgres' behaviour is correct.

Thanks. I believe that I addressed this in a separate branch in this thread. The distinction (between « "some key": null » and "some key" absent), which by all means matters in some contexts, does not matter w.r.t. the requirements of my (demo) app. And I've now proved (to myself, at least) that I can meet my goal easily with existing Postgres features—especially "jsonb_strip_nulls()".

I hope that this means that we're all happy.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message houzj.fnst@fujitsu.com 2022-06-20 03:31:37 RE: Support logical replication of DDLs
Previous Message David G. Johnston 2022-06-20 01:10:38 Re: Outer joins and NULLs (old subject "ERROR: failed to find conversion function from key_vals_nn to record[]")