0

I have a table with an integer array column. I want to select all rows where contains at least one int value from a given list.

E.g.

SELECT * FROM table where (111) = ANY (columarray)

returns all rows where columnarray contains 111.

Now I want select all rows where columnarray contains 111 or/and 222. Something like

SELECT * FROM table where (111,222) = ANY (columnarray)

that doesnt work. It returns an error

Error: ERROR: operator does not exist: record = integer Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. Position: 45 SQLState: 42883 ErrorCode: 0

1 Answer 1

5

You can use the array overlap operator:

SELECT *
FROM table 
WHERE ARRAY[111, 222] && columnarray;
Sign up to request clarification or add additional context in comments.

1 Comment

Do you know how i can parameterize the ARRAY values wit JPA? I try to use a NativeQuery. ARRAY:values and setParameter('values', valuesArray) doesnt work.

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.