RE: JSONB arrays - Mailing list pgsql-general

From Steven Winfield
Subject RE: JSONB arrays
Date
Msg-id E9FA92C2921F31408041863B74EE4C2001AEFC4E43@CCPMAILDAG03.cantab.local
Whole thread Raw
In response to JSONB arrays  (Victor Noagbodji <vnoagbodji@amplify-nation.com>)
List pgsql-general
From: Victor Noagbodji [mailto:vnoagbodji@amplify-nation.com]
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.
 

pgsql-general by date:

Previous
From: Steven Winfield
Date:
Subject: RE: Index Gin Creation is taking long time..
Next
From: Thiemo Kellner
Date:
Subject: Re: Database name with semicolon