title: Flattening a nested json[b] array in Postgres
body: <p>I have <code>jsonb</code> column <code>feeds</code> with data in the form of this:</p>
  
  <pre><code>[{
    "id": 99999999,
    "lang": "pt",
    "entities": {
      "urls": [],
      "media": [{
        "id": 123456456,
        "type": "photo",
        "id_str": "123456456",
        "indices": [37, 59],
      }]
    },
    "favorited": false,
    "retweeted": false,
    "truncated": false
  }]
  </code></pre>
  
  <p>How do I query the <strong>first</strong> <code>media -&gt;&gt; id</code> since it's in an json array? So that the result is like this:</p>
  
  <pre><code>   id             media_id
  ---------------------------
  99999999         123456456
  </code></pre>
  
  <p>I tried <code>jsonb_array_elements</code> but can't seem to get the output I want, especially the part where the <code>media</code> is nested within another array.</p>