Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if array is contained in another array in PostgreSQL

There is an array[10,20] and I want to know if it is a subset of array[20,30,10] or not. Is there a postgresql function or operation to determine if one array contains another?

Desired outcomes:

[10,20] and [30,20,10] - true
[10,20] and [10,30]    - false
[10,20] and [20,10]    - true
[10,20] and [10,20]    - true
like image 440
edem Avatar asked Jan 04 '14 16:01

edem


1 Answers

Like this,perhaps:

SELECT ARRAY[10,20]  <@ ARRAY[30,20,10];

http://www.postgresql.org/docs/current/static/functions-array.html

like image 128
Michael Krelin - hacker Avatar answered Sep 21 '22 16:09

Michael Krelin - hacker