Arrays PostgreSQL:处理数组

Arrays PostgreSQL:处理数组,arrays,postgresql,Arrays,Postgresql,我在PostgreSQL表中有一个可用的列,其类型为数组:text[] select available_sizes from products; {37,38,39,40} ... 有时我需要检查哪些行包含某些值,例如39和40,因此我尝试这样做: select * from products where available_sizes && ('{39, 40}'); 返回包含39或40的行 select * from products where avail

我在PostgreSQL表中有一个可用的列,其类型为数组:text[]

select available_sizes from products;

 {37,38,39,40}
...
有时我需要检查哪些行包含某些值,例如39和40,因此我尝试这样做:

select * 
from products 
where available_sizes && ('{39, 40}');
返回包含39或40的行

select * 
from products 
where available_sizes = ANY ('{41, 42}');
返回错误:“找不到数据类型text[]的数组类型”

请你怎么解决这个问题?对不起,不是SQL/PostgreSQL方面的专家SQL

&&
是“重叠”运算符,即“有共同元素”

您要查找的是“contains”操作符
@>
,它检查右侧数组的所有元素是否都包含在左侧数组中:

select * 
from products 
where available_sizes @> ('{39, 40}');