假设我在表格t中有一个名为value的JSONB列,这些JSON块内部包含一个名为tags的字符串列表字段。
我想查询任何标记为"foo"或"bar"的JSON块。
因此,假设表数据如下:
我想查询任何标记为"foo"或"bar"的JSON块。
因此,假设表数据如下:
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"]}
是否有一种实际的查询方式可以实现这一点,并且这种方式可能会非常快?