alexmorgan.cr
alexmorgan.cr

Reputation: 300

Select plain array against array

I have a table looking like:

Table_A

| name | email_addresses                                 |
| a    | ['[email protected]']                               |
| b    | ['[email protected]', '[email protected]']             |
| c    | ['[email protected]', '[email protected]']         |
| d    | ['[email protected]', '[email protected]', '[email protected]'] |

The field type of email_addresses is JSONB

In simple SQL, my query is like:

select * from Table_A where email_addresses = ['[email protected]', '[email protected]'] 

Which result should be : a, c, d

But not sure how to build this query in postgress json

Upvotes: 0

Views: 41

Answers (1)

emomaliev
emomaliev

Reputation: 2383

You can use the ?| operator to compare the value of your array with the json field

select * from my_table where email_addresses::jsonb ?| array['[email protected]', '[email protected]'];

DBfiddle Deme

Upvotes: 1

Related Questions