0

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

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.