title: JSONB: more than one row returned by a subquery used as an expression
body: <p>I am (still) new to postgresql and jsonb. I am trying to select some records from a subquery and am stuck. My data column looks like this (jsonb):</p>
  
  <pre><code>{"people": [{"age": "50", "name": "Bob"}], "another_key": "no"}
  {"people": [{"age": "73", "name": "Bob"}], "another_key": "yes"}
  </code></pre>
  
  <p>And here is my query. I want to select all names that are "Bob" whose age is greater than 30:</p>
  
  <pre><code>SELECT * FROM mytable
  WHERE (SELECT (a-&gt;&gt;'age')::float
         FROM (SELECT jsonb_array_elements(data-&gt;'people') as a
               FROM mytable) as b 
         WHERE a @&gt; json_object(ARRAY['name', 'Bob'])::jsonb
        ) &gt; 30;
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>more than one row returned by a subquery used as an expression
  </code></pre>
  
  <p>I don't quite understand. If I do some simple substitution (just for testing) I can do this:</p>
  
  <pre><code>SELECT * FROM mytable
  WHERE  (50) &gt; 30  -- 50 is the age of the youngest Bob
  </code></pre>
  
  <p>and that returns both rows.</p>