swift nub
swift nub

Reputation: 2937

How to filter an array using an array with postgresql

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.

Upvotes: 2

Views: 10284

Answers (1)

GMB
GMB

Reputation: 222702

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.

Upvotes: 3

Related Questions