1
假设我在表t
中有一个名为value
的JSONB列,并且这些这些blob中的JSON是tags
字段,它是一个字符串列表。Postgres jsonb数组:查询非空相交
我想查询标记为"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"]}
是否有一个实际的查询可以实现这一点,并且有没有什么方法可能会很快?
[查询JSONB与数组字段]的可能的复制(http://stackoverflow.com/questions/39480863/querying-jsonb-with-array-fields) – Agzam