title: How to use PostgreSQL json_array_elements whit WHERE <value> IN clause
body: <p>I have <code>occasion</code> and <code>relation</code> tables. <code>relation.occasions</code> is a json type field, which contains an array of occasion keys. I want to get <code>occasion</code> records by relation, where <code>occasion.key</code> in <code>relation.occasions</code>. Assume, that this is my DB data:</p>
  
  <p><strong>occasion</strong></p>
  
  <pre><code>        key      |     name      |
  -------------------------------------
      BIRTHDAY     |   Birthday    |
      ANNIVERSARY  |   Anniversary |
  </code></pre>
  
  <p><strong>relation</strong></p>
  
  <pre><code>    key          | occasions                         |
  ------------------------------------------------------
      FATHER       |   [ "BIRTHDAY", "ANNIVERSARY" ]   |
      FRIEND       |   [ "BIRTHDAY" ]                  |
  </code></pre>
  
  <p>Here is the query I'm trying to use:</p>
  
  <pre><code>SELECT * FROM occasion o WHERE o.key IN
  (SELECT json_array_elements(r.occasions)::text from relation r WHERE r.key = 'FATHER')
  </code></pre>
  
  <p>The result is 0 rows instead of expected 2. Can somebody give me a hint what am I doing wrong? How else can I achieve desired result?</p>