简体   繁体   English

如何建立json中缺少属性的postgres json查询?

[英]how to build postgres json query for missing property in json?

I have a table A with a column b as jsonb 我有一个表A,列b为jsonb

        b
------------------
 {"c": 1}
 {"c": 1, "d": 2}

how to build a query for rows where d is missing? 如何为缺少d的行建立查询?

SELECT * FROM A WHERE b@>'{"c":1}';

returns all rows while 返回所有行,而

SELECT * FROM A WHERE b@>'{"c":1,"d":null}';

returns none ( due d is not null in first row ); 不返回任何值(由于d在第一行中不为null);

You can use the ? 您可以使用? operator to test for the presence of a key. 操作员测试是否存在密钥。 To find those where the key does not exist, you can negate the expression: 要查找不存在该密钥的密钥,可以对表达式求反:

select *
from a 
where not b ? 'd';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM