title: Postgres Json(b) int array contains any of array values
body: <p><strong>TLDR: How do I find every record that contains a json number array which contains one number of the given array/list.</strong></p>
  
  <p>Ok, I tried a lot, read a lot of other Threads but I didn't find a working solution yet. I have some JSON Objects in Postgres I'd like to find. They contain the index of a multiple choice select.</p>
  
  <p>Objects:</p>
  
  <pre><code>[{"id": 5, "list": [1, 2, 3]}, {"id": 6, "list": [4, 5, 6]}]
  </code></pre>
  
  <p>And I need so select all objects which contain the Items 1 OR 5. For now, I can only check for one value</p>
  
  <pre><code>SELECT '[1, 2, 3, 4]'::jsonb @&gt; '3'::jsonb as result;
  </code></pre>
  
  <p>or if both are present:</p>
  
  <pre><code>SELECT '[1,2,3,4]'::jsonb @&gt; '[1, 2]'::jsonb as result;
  </code></pre>
  
  <p>Or, the interesting thing, if I have an array of strings, I can do what I need:</p>
  
  <pre><code>SELECT '["1","2","3","4"]'::jsonb ?| array['1', '5'] as result;
  </code></pre>
  
  <p>How do I apply this to JSON number arrays? I tried casting to int[] and a lot of other stuff. Nothing worked. I either need to convert the number array to a text array to work with it or find the right cast for the right side. This also didn't work: <code>?| array[1, 5]::text[]</code></p>
  
  <p><strong>Solution 1:</strong></p>
  
  <p>Well, the first thing that came to my and Mao Tsuns mind, to use <code>OR</code>, still looks like the fastest and simplest solution.</p>
  
  <p><strong>Solution 2:</strong></p>
  
  <p>I finally found a way to do it shorter (like I thought it should work) but it's a casting hell (also 9.4+) and not pretty to look at:</p>
  
  <p><code>SELECT array_to_json(translate('[1,2,3,4]'::jsonb::text, '[]', '{}')::text[])::jsonb ?| array['1','5'] as result;</code></p>
  
  <p>Which basically transforms the integers to strings.</p>