Re: BUG #15763: JSON nulls not handled properly

From: Jacob Crell <jacobcrell(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #15763: JSON nulls not handled properly
Date: 2019-04-16 19:57:38
Message-ID: CADvKwnbAX2w1_HjvRALF34ydwpc5zXnzOrDHtVZ44cTSQEVykg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Thanks for the response. I may have been a bit off in my diagnosis of what
was going wrong. My bug report stemmed from the fact that the below returns
different results, the first throwing an error and the second returning no
rows:

SELECT json_array_elements('{"key":null}'::json->'key')
SELECT json_array_elements(null::json)

This seems unintuitive. Is it potentially a bug?

On Tue, Apr 16, 2019 at 2:35 PM David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

> On Tuesday, April 16, 2019, PG Bug reporting form <noreply(at)postgresql(dot)org>
> wrote:
>
>> The following bug has been logged on the website:
>>
>> Bug reference: 15763
>> Logged by: Jacob Crell
>> Email address: jacobcrell(at)gmail(dot)com
>> PostgreSQL version: 9.6.8
>> Operating system: AWS RDS
>> Description:
>>
>> 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.
>>
>
> This seems under documented but I can confidently say the behavior shown
> is intended and thus not a bug. Nor should it be changed. The second
> example returns a json typed value that when printed as text is the
> character sequence null. It does not return a PostgreSQL string type.
>
> Conversion of json null to PostgreSQL text results in a NULL of type text,
> which is indeed the first outcome. This is, however, a lossy one-way
> conversion since NULL::json is NULL, not ‘null’.
>
> David J.
>
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2019-04-16 20:10:52 Re: BUG #15763: JSON nulls not handled properly
Previous Message David G. Johnston 2019-04-16 19:35:48 Re: BUG #15763: JSON nulls not handled properly