【发布时间】:2018-03-09 02:28:18
【问题描述】:
考虑这个例子:
postgres=# CREATE TABLE emptyarray (fields jsonb);
CREATE TABLE
postgres=# INSERT INTO emptyarray VALUES ('{"key":["a","b"]}');
INSERT 0 1
postgres=# INSERT INTO emptyarray VALUES ('{"key":[]}');
INSERT 0 1
postgres=# SELECT * from emptyarray where Fields@>'{"key":["b"]}';
fields
---------------------
{"key": ["a", "b"]}
(1 row)
postgres=# SELECT * from emptyarray where Fields@>'{"key":[]}';
fields
---------------------
{"key": ["a", "b"]}
{"key": []}
(2 rows)
在第二个查询中,我预计结果中只有一行(包含空数组的一条记录)。但如您所见,结果中有两行。如何使用@> 语法查询空数组?
我使用的是 PostgreSQL 9.6
【问题讨论】:
标签: sql json postgresql postgresql-9.6