5

I have two columns with array type and I would like to check if they have at least one element in common. How can I do it?

For example:

ARRAY[1,4,3] | ARRAY[2,1]

Both arrays contains the number 1, so it should return the row.

1 Answer 1

8

Use the && operator

As described at postgresql official documentation you can use the following command to check if the arrays have one intersection value:

SELECT * FROM mytable m WHERE m.array1 && m.array2

Which, of course, m.array1 and m.array2 are both array types

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.