更新

object_as_json现在是jsonb数据类型

人员表中的一项,有

object_as_json ='{"first":"Joe","last":"Doe","middle":"S","DOB":"1940-01-01"}'

我的查询是(这些都不返回任何内容):

select *
from bw.people
where object_in_json = '{"last":"Doe","first":"Joe"}'

select *
from bw.people
where object_in_json = '{"first":"Joe","last":"Doe","middle":"S","DOB":"1940-01-01"}'

如果您使用jsonb ,则可以编写

WHERE object_in_json @> '{"last":"Doe","first":"Joe"}`

使用json您必须编写

WHERE object_in_json ->> 'last' = 'Doe'
  AND object_in_json ->> 'first' = 'John'
查看全文
  相关解决方案