Re: GENERAL - [How to check if the array contains the element.]

From: Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: GENERAL - [How to check if the array contains the element.]
Date: 2017-04-26 11:33:03
Message-ID: 1dd08db6-8e25-56cb-c483-e5c70dcb363a@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Am 26.04.2017 um 13:24 schrieb VENKTESH GUTTEDAR:
> Hello All,
>
> How do i check if any one element of one array exists in another
> array.
> Eg:
> array1 = [1,2,3,4]
> array2 = [1,4,5,7]
> Now i expect the result as true even if any one element matches
> from array2 in array1.

You can use the overlap - operator:

test=*# select array[1,2,3,4] && array[1,4,5,7];
?column?
----------
t
(1 Zeile)

test=*# select array[1,2,3,4] && array[10,40,50,70];
?column?
----------
f
(1 Zeile)

Regards, Andreas

--
2ndQuadrant - The PostgreSQL Support Company.
www.2ndQuadrant.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message jamesadams89 2017-04-26 12:48:03 BDR replication and table triggers
Previous Message VENKTESH GUTTEDAR 2017-04-26 11:24:25 GENERAL - [How to check if the array contains the element.]