Search Postgresql Archives

RE: JSONB arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Victor Noagbodji [mailto:vnoagbodji@xxxxxxxxxxxxxxxxxx]
Sent: 28 June 2018 11:28
To: pgsql-general
Subject: JSONB arrays
 
Hey people,
 
I ended up with the following to check (or similar to return) the intersection of two list of values on a JSONB object:
 
array_length(
array(
select jsonb_array_elements_text(col1)
intersect
select jsonb_array_elements_text(col2)
), 1) > 0
 
Is there a better way?
 
Thanks
 
 
Try the @> operator:
 
select '[1, 2, 3, 4]'::jsonb @> '[4, 2]'::jsonb
 
 
Steve.
 

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux