From: | Steven Winfield <Steven(dot)Winfield(at)cantabcapital(dot)com> |
---|---|
To: | Victor Noagbodji <vnoagbodji(at)amplify-nation(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | RE: JSONB arrays |
Date: | 2018-06-28 11:47:59 |
Message-ID: | E9FA92C2921F31408041863B74EE4C2001AEFC4E43@CCPMAILDAG03.cantab.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
From: Victor Noagbodji [mailto:vnoagbodji(at)amplify-nation(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Thiemo Kellner | 2018-06-28 12:32:14 | Re: Database name with semicolon |
Previous Message | Steven Winfield | 2018-06-28 11:20:23 | RE: Index Gin Creation is taking long time.. |