Home Return boolean if one element matches among 2 arrays in postgresql
Reply: 2

Return boolean if one element matches among 2 arrays in postgresql

Rogger Barsanulfo Fernandes
1#
Rogger Barsanulfo Fernandes Published in 2017-12-07 12:49:04Z

I have 2 arrays in postgresql and I need to return true if there are at least 1 match of element between these 2 arrays no mather if it is same position.

Follows example below:

select array(select generate_series(0,10)) = 
       any(select array(select generate_series(10,11)))

it should return true because I have 10 in both arrays

Vao Tsun
2#
Vao Tsun Reply to 2017-12-07 12:55:55Z

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

= equal

&& overlap (have elements in common)

formatting mine. You need other operator

select array(select generate_series(0,10)) &&
       any(select array(select generate_series(10,11)));
 ?column?
----------
 t
(1 row)
lat long
3#
lat long Reply to 2017-12-07 13:03:07Z

Go for && operator

like

SELECT ARRAY['apple','cherry','avocado'] && ARRAY['applea','cherrya','avocado']

SELECT ARRAY[1,4,3] && ARRAY[2,1]

https://www.postgresql.org/docs/9.6/static/functions-array.html

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.351337 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO