title: PostgreSQL: Why can't subqueries as expressions return more than one row, but functions can?
body: <p>If I try to create a column whose value is a select returning more than one row, I get an error.</p>
  
  <pre><code>=&gt; select (select 1 union select 2);
  ERROR:  more than one row returned by a subquery used as an expression
  </code></pre>
  
  <p>But if I create a function that does the same thing, I get the behavior I want.</p>
  
  <pre><code>=&gt; create or replace function onetwo() returns setof integer as $$
  $&gt; select 1 union select 2 
  $&gt; $$ language 'sql' strict immutable;
  CREATE FUNCTION
  =&gt; select onetwo();
   onetwo 
  --------
        1
        2
  </code></pre>
  
  <p>Why the difference?</p>