根据数组选择普通数组



我有一个表看起来像:

表_A

| name | email_addresses                                 |
| a    | ['test@test.com']                               |
| b    | ['test@test.com', 'test2@test.com']             |
| c    | ['aatest@test.com', 'bbtest2@test.com']         |
| d    | ['test@test.com', 'test2@test.com', 'aa@bb.cc'] |

电子邮件地址的字段类型为JSONB

在简单的SQL中,我的查询如下:

select * from Table_A where email_addresses = ['test@test.com', 'test2@test.com'] 

哪个结果应该是:a,c,d

但不确定如何在postgress json 中构建此查询

您可以使用?|运算符将数组的值与json字段进行比较

select * from my_table where email_addresses::jsonb ?| array['test@test.com', 'test2@test.com'];

DBfiddle Deme