2016-07-28 38 views
1

如果不使用子查询,我想查找数组中的所有元素是否等于数字的子集。所以,而不是1 = ALL(ARRAY[1,1,1])我想要做一些像ALL(ARRAY[1,1,1]) IN (1, 5)。这可能没有使用select语句?Postgresql ALL IN

回答

0

您想使用@>运算符。

-- does the column contain all of 
select * from test_arrays where values @> array[6, 9]; 
select * from test_arrays where values @> '{6, 9}'::int[]; 

如果你想寻找到阵列中的任何1个值是其他阵列中使用&&操作:

-- does the column contain at-least one of 
select * from test_arrays where values && array[6, 9]; 
select * from test_arrays where values && '{6, 9}'::int[]; 

我碰巧几个月前写这个。

http://www.philliphaydon.com/2016/05/07/postgresql-and-its-array-datatype/