Re: to_json(NULL) should to return JSON null instead NULL

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: to_json(NULL) should to return JSON null instead NULL
Date: 2015-08-29 13:28:51
Message-ID: 55E1B393.1070608@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 08/29/2015 08:47 AM, Shulgin, Oleksandr wrote:
> On Sat, Aug 29, 2015 at 8:39 AM, Pavel Stehule
> <pavel(dot)stehule(at)gmail(dot)com <mailto:pavel(dot)stehule(at)gmail(dot)com>> wrote:
>
> Hi
>
> currently JSON support NULL value - but we doesn't convert NULL to
> JSON correctly
>
> postgres=# select to_json(NULL::text) IS NULL;
> ┌──────────┐
> │ ?column? │
> ╞══════════╡
> │ t │
> └──────────┘
> (1 row)
>
> probably should be json "null";
>
> like
>
> postgres=# select json 'null' is null;
> ┌──────────┐
> │ ?column? │
> ╞══════════╡
> │ f │
> └──────────┘
> (1 row)
>
>
> I agree that for correctness reasons it should, but just don't think
> it would be OK to change this behavior -- the function was there since
> 9.3...
>
> Given there were no loud complaints about this, the current behavior
> is appropriate for most users, the rest can still work around using
> coalesce(to_json(...), json 'null').
>
>

I don't think it's necessarily more correct. But I do agree that it's
not a good idea to change the behaviour unless there is major
unhappiness with it.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Christoph Berg 2015-08-29 13:38:51 Re: 9.4 broken on alpha
Previous Message Shulgin, Oleksandr 2015-08-29 13:14:34 Re: Proposal: Implement failover on libpq connect level.