1

Looking for a way to check if one of the items of given array exists in db property, which is also an array. I have a table 'Events', which has a property weekDays, which is an array of numbers [1,2,3,4,5]. Given an array searchDays which is [2,3], I want to check if the one of the items exists in weekDays.

2 Answers 2

2

This means you need to look for overlap. The operator is &&

SELECT * FROM Events where weekDays && ARRAY[2,3]
Sign up to request clarification or add additional context in comments.

Comments

1

you are looking for intersecion I suppose:

t=# with c(weekdays,searchdays) as (values(array[1,2,3,4,5],array[2,3]))
select weekdays && searchdays from c;
 ?column?
----------
 t
(1 row)

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.