title: Why are "subqueries used as an expression" allowed to return a SETOF something but not a TABLE?
body: <p>So I have a table with some arrays of integers.</p>
  
  <pre><code>CREATE TABLE arrays (
    nums int[],
    id serial PRIMARY KEY
  );
  
  INSERT INTO arrays VALUES
    ('{1, 5, 72}', 1),
    ('{3}', 2),
    ('{32, 6}', 3);
  </code></pre>
  
  <p>If I want to spread those array elements to separate rows, I can do it with a function that returns a SETOF INT, such as <code>unnest</code>.</p>
  
  <pre><code>SELECT
    id,
    unnest(nums)
  FROM arrays;
  
  -- id   unnest
  -- 1    1
  -- 1    5
  -- 1    72
  -- 2    3
  -- 3    32
  -- 3    6
  </code></pre>
  
  <p>But I always thought that subqueries inside a SELECT clause <strong>had</strong> to return a single value! Yet <code>unnest</code> is returning multiple values. Postgres just handles it by duplicating the row for each value. But if I try another subquery that returns multiple values, like this:</p>
  
  <pre><code>SELECT
    a.id,
    (SELECT a.nums[1] UNION SELECT a.nums[2])
  FROM arrays a;
  
  -- ERROR: more than one row returned by a subquery used as an expression
  </code></pre>
  
  <p>That gives an error. It seems like it should be handled in an analogous manner to <code>unnest</code>. <strong>Why is <code>unnest</code> allowed to return multiple values but not this?</strong></p>