Reputation: 37045
I have a table with a column tags
of type varchar []
.
I would like to select all rows where the tags contains at least one of a set of values.
Something like this:
-- Not real code
SELECT *
FROM foo
WHERE non_empty(set_intersection(tags, '{ "apples", "bananas", "cherries" }'))
What is the syntax for this?
I know I can do a series of OR
s but that seems less elegant.
Upvotes: 11
Views: 5034
Reputation: 222482
You can use &&
, the array overlap operator:
select *
from foo
where tags && ARRAY['apples', 'bananas', 'cherries']
From the documentation:
&&
: overlap (have elements in common)
Upvotes: 16