Re: BUG #14354: Wrong interpretation of JSON 'null'
От | Vitaly Burovoy |
---|---|
Тема | Re: BUG #14354: Wrong interpretation of JSON 'null' |
Дата | |
Msg-id | CAKOSWN=EQk2+SO00TOp-_QRktZxrUhxGzVdN5hjGKnLfcfij6w@mail.gmail.com обсуждение исходный текст |
Ответ на | BUG #14354: Wrong interpretation of JSON 'null' (kouber@gmail.com) |
Ответы |
Re: BUG #14354: Wrong interpretation of JSON 'null'
|
Список | pgsql-bugs |
On 10/5/16, kouber@gmail.com <kouber@gmail.com> wrote: > The following bug has been logged on the website: > > Bug reference: 14354 > Logged by: Kouber Saparev > Email address: kouber@gmail.com > PostgreSQL version: 9.4.5 > Operating system: Fedora > Description: > > Trying to pass 'null' to jsonb_each_text() results in an ERROR, while at the > same time it is considered a valid JSON value. This behaviour seems quite > inconsistent - either such a value should be considered invalid in general, > either the function should treat it as a normal NULL instead. > > db=# select 'null'::jsonb; > jsonb > ------- > null > (1 row) > > db=# select jsonb_each_text('null'::jsonb); > ERROR: cannot call jsonb_each_text on a non-object > > db=# select jsonb_each_text(NULL); > jsonb_each_text > ----------------- > (0 rows) It is not a bug. It works as expected. 1. NULL::jsonb is not the same as 'null'::jsonb PG's NULL (not jsonb's 'null'!) as input returns NULL output. 2. Argument for jsonb_each_text should be a jsonb with an _json-object_ at top-level (see types of primitives by [1] and [2]), e.g. '{"key1":"value1", "key2":"value2"}' to produce pairs (key, value). Your example has jsonb value with a null-value at top-level. The same exception is raised if you send a json-string as an input: db=# select jsonb_each_text('"str"'::jsonb); ERROR: cannot call jsonb_each_text on a non-object P.S.: what you're expecting from the "select jsonb_each_text('null'::jsonb)" call? [1] https://www.postgresql.org/docs/9.6/static/datatype-json.html#JSON-TYPE-MAPPING-TABLE [2] https://www.postgresql.org/docs/9.6/static/datatype-json.html#JSON-KEYS-ELEMENTS -- Best regards, Vitaly Burovoy
В списке pgsql-bugs по дате отправления: