JSON NULLs

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: JSON NULLs
Date: 2013-02-06 19:08:38
Message-ID: A62DDF0A-81DF-4988-9440-F038B46D60D6@justatheory.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hackers,

While playing with Andrew’s JSON enhancements, I noticed this:

david=# select * From json_each_as_text('{"baz": null}'::json);
key | value
-----+-------
baz | null

It is returning 'null'::text there, not NULL::text. I had expected the latter, because otherwise it's not possible to tell the difference between '{"foo": null}' and '{"foo": "null"}'.

But then I noticed that this seems to be true for JSON NULLs in general:

david=# select 'null'::json::text IS NULL;
?column?
----------
f

Again, I expected a NULL there. I recognize that JSON NULLs are not the same as SQL NULLs, but if there is no way to tell the difference, well, it’s annoying.

I see that '"null"'::json::text resolves to '"null"'::text, so that’s one way to deal with it. But since json_each_as_text returns values as text, not quoted JSON values, maybe *it* should return JSON NULLs as SQL NULLs?

Thanks,

David

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dev Kumkar 2013-02-06 19:19:21 Re: Facing authentication error on postgres 9.2 -> dblink functions
Previous Message Alvaro Herrera 2013-02-06 18:51:15 Re: palloc unification