考虑这个例子:
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 - 如何在 JSONB 中查询空数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46450606/