Kouber Saparev <kouber@gmail.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