From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: '{"x": 42, "y": null}'::jsonb != '{"x": 42}'::jsonb ... Really?
Date: Sat, 04 Jun 2022 01:37:43 -0400
Message-ID: <426968.1654321063@sss.pgh.pa.us> (raw)
In-Reply-To: <C5A701D6-50AC-4561-B64C-318DBF52A312@yugabyte.com>
References: <7E0BF7DF-CC12-48B6-8550-9C2B5A8F78B1@yugabyte.com>
<CAKFQuwbrQGuGVdZR=aNOPAhoGYJiqvJK69vFk3w4oQ1_apuT8w@mail.gmail.com>
<C5A701D6-50AC-4561-B64C-318DBF52A312@yugabyte.com>
Bryn Llewellyn <bryn@yugabyte.com> writes:
> I'm going to try to think like this:
> The number of possible spellings of the names of keys in a JSON object is some flavor of infinite. So including this in an object:
> "k": null
> really is saying something. It says that I do know about "k" and that yet I have simply no information available about its value.
I'd read it as asserting that key "k" is meaningful for this object,
but the correct value for that key is not known.
I have a hard time with your assertion that {"x": 42, "y": null}
should be considered equivalent to {"x": 42}, because it would
render key-exists predicates useless. Either you have to say that
key "y" is claimed to exist in both of these objects and indeed every
object, or you have to make it fail if the key's value is null (so that
it'd say "false" in both of these cases). Either of those options
seems both weird and useless.
> The quirkiness that my first example showed can be seen differently from how I saw it first. When I now consider this expression:
> ('{"x": 42}'::jsonb)->>'y'
> it seems that its evaluation should simply raise an exception. But you said:
>> This produces "key y not present in JSON" but someone decided that was too unfriendly and so we instead produce SQL NULL.
Right. This is hard to justify from a purist semantic point of view,
but having the operator throw an error in such cases would make it
close to unusable on not-uniformly-structured data. And really the
point of using JSON inside a SQL database is to cope with irregularly-
structured data, so fuzziness seems like what we want.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, bryn@yugabyte.com, david.g.johnston@gmail.com
Subject: Re: '{"x": 42, "y": null}'::jsonb != '{"x": 42}'::jsonb ... Really?
In-Reply-To: <426968.1654321063@sss.pgh.pa.us>
References: <7E0BF7DF-CC12-48B6-8550-9C2B5A8F78B1@yugabyte.com> <CAKFQuwbrQGuGVdZR=aNOPAhoGYJiqvJK69vFk3w4oQ1_apuT8w@mail.gmail.com> <C5A701D6-50AC-4561-B64C-318DBF52A312@yugabyte.com> <426968.1654321063@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox