我有一个数组:{"test1",test2,test3}
表
id tags
1 test4
2 test2
3 test3,test2
4 test1,test2
5 test1,test2,test3
6 test2,test1,test2
我的条件是匹配数组中是否存在所有标签。如果是,则选择所有这些记录。
所以这里上面场景的结果应该是
2,3,4,5,6
答案 0 :(得分:2)
对数组使用contains运算符:
select id
from the_table
where string_to_array(tags, ',') <@ array['test1', 'test2', 'test3'];
答案 1 :(得分:1)
SELECT id FROM t
WHERE ANY(regexp_split_to_array(tags, ','))=ANY ( {"test1","test2","test3"})