我有一个带有jsonb字段的表。内容如下:
select myfield from mytable
{"1": [1, 2, 3], "2": [1, 2], "3": [1, 2], "4": true}
{}
{"1": [6, 11]}
{"3": [2], "4": true}
到目前为止,我已经设法运行如下查询:
-- Select all rows that, for key "1", are null
select addl from live_feeds where (addl->>'1') is null
-- Select all rows that, for key "4", are true
select addl from live_feeds where (addl->>'4')::boolean is true;
但是尝试了几种不同的方法之后,我无法使这种方法起作用:
Select all rows that, for key "1", include value 1
我应该使用哪种类型的演员/操作员?
答案 0 :(得分:1)
您可以这样做(function json doc)
@>
:左侧的JSON值中是否包含右侧的值?
select addl from live_feeds where (addl->>'1')::jsonb @> '[1]'