2

I'm using postgresql. How can I check if a cell (type integer[]) contains a certain value? There is a cell (row_of_type_integer_array) is a row of type integer[]. There is one cell containing the values {2, 3, 4}

Now I want sth like: if there is a cell containg the value 2 (not only 2, but also 2), then return sth. This would be the case in the given cell mentioned above.

I tried this:

SELECT id FROM table_name WHERE row_of_type_integer_array = 2;

However this isn't working. I also tried this:

SELECT id FROM table_name WHERE 2 IN row_of_type_integer_array;

But this isn't working either. Which way can I go else?

1 Answer 1

2

Many ways to do it. Here's one:

SELECT id FROM table WHERE 2 = ANY(row_of_type_integer_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.