Is there a jsonb array overlap function for postgres?
<p>Am not able to extract and compare two arrays from jsonb in postgres to do an overlap check. Is there a working function for this?</p>

<p>Example in people_favorite_color table:</p>

<pre><code>{
    "person_id":1,
    "favorite_colors":["red","orange","yellow"]
}
{
    "person_id":2,
    "favorite_colors":["yellow","green","blue"]
}
{
    "person_id":3,
    "favorite_colors":["black","white"]
}
</code></pre>

<p>Array overlap postgres tests:</p>

<pre><code>select 
p1.json_data-&gt;&gt;'person_id',
p2.json_data-&gt;&gt;'person_id',
p1.json_data-&gt;'favorite_colors' &amp;&amp; p2.json_data-&gt;'favorite_colors'
from people_favorite_color p1 join people_favorite_color p2 on (1=1)
where p1.json_data-&gt;&gt;'person_id' &lt; p2.json_data-&gt;&gt;'person_id'
</code></pre>

<p>Expected results:</p>

<pre><code>p1.id;p2.id;likes_same_color
1;2;t
1;3;f
2;3;f
</code></pre>

<p>--edit--
Attempting to cast to text[] results in an error:</p>

<pre><code>select
('{
        "person_id":3,
        "favorite_colors":["black","white"]
}'::jsonb-&gt;&gt;'favorite_colors')::text[];

ERROR:  malformed array literal: "["black", "white"]"
DETAIL:  "[" must introduce explicitly-specified array dimensions.
</code></pre>