3

I'm using postgres 9.5 and have a table that looks something like this:

+----+--------------+-------------------------------+
| id | string_field | array_field                   |
|----+--------------+-------------------------------|
| 1  | string a     | [apple, orange, banana, pear] |
| 2  | string b     | [apple, orange, banana]       |
| 3  | string c     | [apple, orange]               |
| 4  | string d     | [apple, pear]                 |
| 5  | string e     | [orange, apple]               |
+----+--------------+-------------------------------+

Is it possible to query the DB for rows where array_field is, or contains [apple, orange, banana]? The results should return rows with id 1 and 2.

1 Answer 1

5

Try something like this:

where array_field @> ARRAY['apple', 'orange', 'banana']::varchar[]

Documentation

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

2 Comments

Thanks for the answer. I've realized I actually have an array in a jsonb column, what would the syntax look like for that?
I've got it: select * from tmp where jsonb_column @> '["apple", "orange", "banana"]'::jsonb;

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.