Re: BUG #15763: JSON nulls not handled properly

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jacobcrell(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15763: JSON nulls not handled properly
Date: 2019-04-16 19:29:00
Message-ID: 5901.1555442940@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2019-04-16 19:35:48 Re: BUG #15763: JSON nulls not handled properly
Previous Message PG Bug reporting form 2019-04-16 19:13:13 BUG #15763: JSON nulls not handled properly