Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eSMfo-0005RH-4q for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Dec 2017 12:43:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eSMfn-0005RY-Lp for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Dec 2017 12:43:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eSMfn-0005RO-GK for pgsql-bugs@lists.postgresql.org; Fri, 22 Dec 2017 12:43:35 +0000 Received: from [120.132.35.202] (helo=exchange44.qunarservers.com) by magus.postgresql.org with esmtps (TLS1.0:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eSMfg-0004H0-Pj for pgsql-bugs@postgresql.org; Fri, 22 Dec 2017 12:43:33 +0000 Received: from [10.86.14.156] (10.86.14.156) by exchange44.qunarservers.com (10.90.4.18) with Microsoft SMTP Server (TLS) id 14.3.224.2; Fri, 22 Dec 2017 20:43:19 +0800 To: From: yunlong.gao Subject: May be a jsonb type bug Message-ID: Date: Fri, 22 Dec 2017 20:43:19 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------A254B3D0A741BFC6327E616E" Content-Language: en-US X-Originating-IP: [10.86.14.156] X-Host-Lookup-Failed: Reverse DNS lookup failed for 120.132.35.202 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --------------A254B3D0A741BFC6327E616E Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit 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) -- *PostgreSQL DBA yunlong.gao * pg开发指南 http://wiki.corp.qunar.com/pages/viewpage.action?pageId=58058230 pg发布流程 http://wiki.corp.qunar.com/pages/viewpage.action?pageId=56215301 pg值班列表 http://wiki.corp.qunar.com/pages/viewpage.action?pageId=50508626 pg机器列表 http://wiki.corp.qunar.com/pages/viewpage.action?pageId=36438672 pgbouncer http://wiki.corp.qunar.com/display/searchdev/pgbouncer+server --------------A254B3D0A741BFC6327E616E Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: 8bit

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)

--------------A254B3D0A741BFC6327E616E--