【发布时间】:2016-09-14 00:27:46
【问题描述】:
假设我在表 t 中有一个名为 value 的 JSONB 列,并且在这些 JSON 块内部是一个 tags 字段,它是一个字符串列表。
我想查询任何标记为 "foo" 或 "bar" 的 JSON blob。
所以假设表格数据如下所示:
value
---------------------
{"tags": ["other"]}
{"tags": ["foo", "quux"]}
{"tags": ["baz", "bar"]}
{"tags": ["bar", "foo"]}
{"tags": []}
我想写一些这样的查询:
select value from t where value->'tags' NONEMPTY_INTERSECTION '["foo", "bar"]'
这样的结果将是:
value
-----------------------
{"tags": ["foo", "quux"]}
{"tags": ["baz", "bar"]}
{"tags": ["bar", "foo"]}
是否有一个实际的查询可以完成此操作,有什么方法可以快速完成吗?
【问题讨论】:
标签: postgresql jsonb