Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nxMU2-0003jT-2A for pgsql-general@arkaria.postgresql.org; Sat, 04 Jun 2022 05:37:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nxMTz-0007MR-J8 for pgsql-general@arkaria.postgresql.org; Sat, 04 Jun 2022 05:37:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nxMTz-0007MG-8K for pgsql-general@lists.postgresql.org; Sat, 04 Jun 2022 05:37:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nxMTq-0002pw-N5 for pgsql-general@lists.postgresql.org; Sat, 04 Jun 2022 05:37:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2545bhCE426969; Sat, 4 Jun 2022 01:37:43 -0400 From: Tom Lane To: Bryn Llewellyn cc: "David G. Johnston" , pgsql-general list Subject: Re: '{"x": 42, "y": null}'::jsonb != '{"x": 42}'::jsonb ... Really? In-reply-to: References: <7E0BF7DF-CC12-48B6-8550-9C2B5A8F78B1@yugabyte.com> Comments: In-reply-to Bryn Llewellyn message dated "Fri, 03 Jun 2022 21:45:52 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <426967.1654321063.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 04 Jun 2022 01:37:43 -0400 Message-ID: <426968.1654321063@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bryn Llewellyn writes: > I'm going to try to think like this: > The number of possible spellings of the names of keys in a JSON object i= s 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 ye= t 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 s= aid: >> 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