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