pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jacobcrell@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15763: JSON nulls not handled properly
Date: Tue, 16 Apr 2019 15:29:00 -0400
Message-ID: <5901.1555442940@sss.pgh.pa.us> (raw)
In-Reply-To: <15763-200acd20c49eeff5@postgresql.org>
References: <15763-200acd20c49eeff5@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> 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





view thread (5+ messages)  latest in thread

Message-ID: <5901.1555442940@sss.pgh.pa.us>
Permalink:  ../5901.1555442940@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5901.1555442940@sss.pgh.pa.us

 · 

reply

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jacobcrell@gmail.com
  Subject: Re: BUG #15763: JSON nulls not handled properly
  In-Reply-To: <5901.1555442940@sss.pgh.pa.us>
  References: <15763-200acd20c49eeff5@postgresql.org> <5901.1555442940@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