2016-07-28 52 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/