1

Below is my postgres 9.3 table

      id    arr
      1     [1,2,3]
      2     [1,2]
      3     [1]
      4     [2]
      5     [4,5,6]

If i search for 1,2 i am expecting output as below. I want all the rows which either contains 1 or 2.

  id    arr
  1     [1,2,3]
  2     [1,2]
  3     [1]
  4     [2]

I tried using below query i.e. using ANY

  Select * from test where arr = ANY ('{1,2}'::int[])

It gives an error

 ERROR: operator does not exist: integer[] = integer Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. Position: 30

How do I achieve this?

SQLFiddle - http://sqlfiddle.com/#!15/63c4f/4

1 Answer 1

1

Use the overlap operator:

Select * from test where arr && '{1,2}'::int[]
Sign up to request clarification or add additional context in comments.

1 Comment

You are the savior :)

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.