11

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 ORs but that seems less elegant.

1 Answer 1

17

You can use &&, the array overlap operator:

select *
from foo
where tags && ARRAY['apples', 'bananas', 'cherries']

From the documentation:

&&: overlap (have elements in common)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.