Re: BUG #14354: Wrong interpretation of JSON 'null'

From: Kouber Saparev <kouber(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14354: Wrong interpretation of JSON 'null'
Date: 2016-10-06 15:27:47
Message-ID: CAN4RuQsL=Zp_W0fZGhT_UptvY+uPDFGOkx5zv15bbBt2a3LGSw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

It looks like I do not know enough about the JSON type and I was treating
it always like an object with keys and values. You are absolutely correct,
now I see that I can really:

db=# select '2'::jsonb;
jsonb
-------
2
(1 row)

Which explains everything.

Cheers,

2016-10-06 15:47 GMT+03:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

> Kouber Saparev <kouber(at)gmail(dot)com> writes:
> > Okay, I also saw in the source code that it is looking for an
> _json-object_
> > (whatever that means) and is throwing that error otherwise. The thing is
> -
> > in my perception the string 'null' , being valid json(b), should also be
> > treated as valid _json-object_, isn't it?
>
> No. A JSON "object" is something with field names and values, like a
> Perl hash. JSON also has scalars and arrays; those are JSON values,
> but not JSON objects. 'null' is a scalar, I think, although for some
> purposes it might be better to view it as a fourth primitive kind of
> JSON value.
>
> jsonb_each_text() needs to work on a JSON object because otherwise its
> return convention of returning a set of field names and values makes
> no sense. What would you imagine jsonb_each_text('2'::jsonb) ought
> to do? Similarly, there's not really any sensible interpretation
> of jsonb_each_text('null'::jsonb).
>
> > ... I felt its an
> > inconsistency in PostgreSQL itself.
>
> The distinction between objects and other kinds of JSON values is
> drawn in the JSON standard; we did not make it up. See
> http://rfc7159.net/rfc7159
>
> regards, tom lane
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2016-10-06 17:56:56 Re: BUG #14351: Upsert not working in case of partitioned tables
Previous Message Kevin Grittner 2016-10-06 14:15:59 Re: BUG #14243: pg_basebackup failes by a STATUS_DELETE_PENDING file