May be a jsonb type bug - Mailing list pgsql-bugs

From yunlong.gao
Subject May be a jsonb type bug
Date
Msg-id ae4325cd-4e99-b9d0-34f7-55ebe8f1a028@qunar.com
Whole thread Raw
Responses Re: May be a jsonb type bug  (Sergei Kornilov <sk@zsrv.org>)
List pgsql-bugs

Hi all:

When i exec function jsonb_array_length(jsonb),The database throw a error: cannot get array length of a scalar
That's because have a 'null' value in the jsonb type column

So i have a test and think null is a bug for jsonb:

mydb=# \d test
                                       Table "public.test"
  Column  |            Type             | Collation | Nullable |             Default             
----------+-----------------------------+-----------+----------+----------------------------------
 id       | integer                     |           | not null | nextval('test_id_seq'::regclass)
 info     | text                        |           |          |
 crt_time | timestamp without time zone |           |          |
 col_n    | jsonb                       |           |          |
Indexes:
    "test_pkey" PRIMARY KEY, btree (id)

mydb=# update test set col_n='test' where id=1;
ERROR:  invalid input syntax for type json
LINE 1: update test set col_n='test' where id=1;
                              ^
DETAIL:  Token "test" is invalid.
CONTEXT:  JSON data, line 1: test


mydb=# update test set col_n='null' where id=1;
UPDATE 1
mydb=#
mydb=#
mydb=# select * from test where id=1;
 id | info |          crt_time          | col_n
----+------+----------------------------+-------
  1 | test | 2017-12-13 15:14:16.347681 | null
(1 row)

pgsql-bugs by date:

Previous
From: Stephen Frost
Date:
Subject: Re: BUG #14986: -2147483648 is minimum value of integer but-2147483648::integer fails (out of range).
Next
From: Sergei Kornilov
Date:
Subject: Re: May be a jsonb type bug