尋找找到某個json列包含空對象的所有行,{}
。這可以用JSON數組,或者如果我正在尋找對象中的特定鍵。但我只想知道對象是否爲空。似乎無法找到一個能夠做到這一點的運營商。如何查詢空對象的json列?
dev=# \d test
Table "public.test"
Column | Type | Modifiers
--------+------+-----------
foo | json |
dev=# select * from test;
foo
---------
{"a":1}
{"b":1}
{}
(3 rows)
dev=# select * from test where foo != '{}';
ERROR: operator does not exist: json <> unknown
LINE 1: select * from test where foo != '{}';
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
dev=# select * from test where foo != to_json('{}'::text);
ERROR: operator does not exist: json <> json
LINE 1: select * from test where foo != to_json('{}'::text);
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
dwv=# select * from test where foo != '{}'::json;
ERROR: operator does not exist: json <> json
LINE 1: select * from test where foo != '{}'::json;
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
新鮮出爐:http://www.postgresql.org/about/news/1557/ – opyate
可能很明顯,但這適用於空陣列以及用[] – hobberwickey
代替{}如果您正在尋找嵌套結構,下面可能是你可以使用的東西:'select * from test where foo - >>'property'='[]';'結構可能類似於:'{「property」:[],「 foo「:」bar「}' – Dynom