1

I have a column which is of an array type. I want to use the where condition in my script, but am unable to. The unnest formula is too complex to use and I want to keep it simple here.

I have 4 columns. One of them is called box_number. It can have an array of multiple numbers. I want to search for rows where box_number contains 123.

select
*
from BOX_TABLE
where box_number is {123}

ERROR: syntax error at or near "{"

0

2 Answers 2

4
SELECT * FROM BOX_TABLE WHERE 123 = ANY (box_number);

You check that at least one value inside the column is 123.

Sign up to request clarification or add additional context in comments.

Comments

3

To test for equality, try

WHERE box_number = ARRAY[123]

To test if the array contains your value, use the “contains” operator &&:

WHERE box_number && ARRAY[123]

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.