2

I have a Postgres DB and I have table A with a field category which is a string Array. How do i find all records on Table A whose category array field contains the all the strings in this array? --> ['test1', 'test2'].

Searching on google give me only when category is a String. But in my case it is an array.

1 Answer 1

3

You can use array containment operator @>:

select * from a where category @> array['test1', 'test2']

This ensures that category contains all elements of the right operand.

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.