Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGToW-0002EI-IN for pgsql-bugs@arkaria.postgresql.org; Tue, 16 Apr 2019 19:32:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hGToU-00042B-Dj for pgsql-bugs@arkaria.postgresql.org; Tue, 16 Apr 2019 19:32:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGTlR-0007bl-OE for pgsql-bugs@lists.postgresql.org; Tue, 16 Apr 2019 19:29:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGTlP-0006aJ-H4 for pgsql-bugs@lists.postgresql.org; Tue, 16 Apr 2019 19:29:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x3GJT0pf005902; Tue, 16 Apr 2019 15:29:00 -0400 From: Tom Lane To: jacobcrell@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15763: JSON nulls not handled properly In-reply-to: <15763-200acd20c49eeff5@postgresql.org> References: <15763-200acd20c49eeff5@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 16 Apr 2019 19:13:13 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5900.1555442940.1@sss.pgh.pa.us> Date: Tue, 16 Apr 2019 15:29:00 -0400 Message-ID: <5901.1555442940@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > SELECT '{"test":null}'::json->>'test' will return a null > SELECT '{"test":null}'::json->'test' will return a string 'null' > The 2nd option seems like it should also return a null. I don't claim to be a JSON expert, but the -> operator is specified to give back a JSON value (not a text string). So 'null'::json seems like the right answer there. Also, if we had it return a NULL, then you couldn't distinguish the case where the field isn't present: regression=# SELECT '{"test":null}'::json->'notthere'; ?column? ---------- (1 row) regression=# SELECT '{"test":null}'::json->'notthere' is null; ?column? ---------- t (1 row) regards, tom lane