title: Why can't I query directly on jsonb_array_elements?
body: <p>I have data stored as jsonb in a column called "data":</p>
  
  <pre><code>{'people': [{"name": "Bob", "Occupation": "janitor"}, {"name": "Susan", "Occupation", "CEO"}]}
  </code></pre>
  
  <p>I can query this via:</p>
  
  <pre><code>SELECT mydata.pk FROM mydata, jsonb_array_elements(mydata.data-&gt;'people') AS a WHERE (a-&gt;&gt;'name') = 'bob' 
  </code></pre>
  
  <p>Why can't I substitute "a" for the jsonb_array_elements(...)?:</p>
  
  <pre><code>SELECT mydata.pk FROM mydata WHERE (jsonb_array_elements(mydata.data-&gt;'people')-&gt;&gt;'name') = 'bob' 
  </code></pre>
  
  <p>Instead, I get the following:</p>
  
  <pre><code>ERROR:  argument of WHERE must not return a set
  </code></pre>