PostgreSQL check if array contains any element from left-hand array
Assuming that your inputs are arrays but it is okay to unwrap them using unnest()
, here is a solution:
SELECT count(*)>0
FROM
(SELECT unnest('{2,3}'::int[]) a1) t1
join (SELECT unnest('{1,3,4,7}'::int[]) a2) t2
on t1.a1=t2.a2;
Sure, use the &&
array-overlaps operator:
SELECT ARRAY[1,2] && ARRAY[1,3,4,7];
See array functions and operators.