1

I have a table in postgre SQL like this which using 1 dimentional integer data type in array column

+----+--------+-----------+
| id |  name  |   array   |
+----+--------+-----------+
|  1 | apple  | {1, 2, 3} |
|  2 | mango  | {2, 3, 4} |
|  3 | banana | {4, 5, 6} |
+----+--------+-----------+

and I want to do a query to find every rows with array column contains at least one number from my list of number. For example, search each array to see if it contains 2, 4

Is there any better solution than using query like this?

SELECT * FROM table WHERE 2 = ANY (array) OR 4 = ANY (array)

1 Answer 1

2

You can try the following:

SELECT *
FROM yourTable
WHERE '{1,4}' && array
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.