title: Unnest array by one level
body: <p>I want to take an array of <code>n</code> dimensions and return set containing rows of arrays of <code>n-1</code> dimensions. For example, take the array <code>ARRAY[[1,2,3], [4,5,6], [7,8,9]]</code> and return a set <code>{1,2,3}, {4,5,6}, {7,8,9}</code>. Using unnest returns the set <code>1,2,3,4,5,6,7,8,9</code>.</p>
  
  <p>I tried grabbing the unnest function from PostgreSQL 8.4, which seems like it would do what I'm looking for:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION tstng.unnest2(anyarray)
      RETURNS SETOF anyelement
      LANGUAGE plpgsql
      IMMUTABLE
      AS $$
      BEGIN
              RETURN QUERY SELECT $1[i]
                  FROM generate_series(array_lower($1,1), array_upper($1,1)) i;
          END;
      $$;
  </code></pre>
  
  <p>However, <code>SELECT tstng.unnest2(ARRAY[[1,2,3], [4,5,6], [7,8,9]]);</code> returns the set <code>, ,</code> (i.e.: 3 null rows).</p>
  
  <p>I've also found that <code>SELECT (ARRAY[[1,2,3], [4,5,6], [7,8,9]])[0];</code> returns null, which I believe to be the root of my problem.</p>