<returnvalue>setof anyelement</returnvalue>
</para>
<para>
- Expands an array to a set of rows.
+ Expands an array into a set of rows.
+ The array's elements are read out in storage order.
</para>
<para>
<literal>unnest(ARRAY[1,2])</literal>
<programlisting>
1
2
+</programlisting>
+ </para>
+ <para>
+ <literal>unnest(ARRAY[['foo','bar'],['baz','quux']])</literal>
+ <returnvalue></returnvalue>
+<programlisting>
+ foo
+ bar
+ baz
+ quux
</programlisting>
</para></entry>
</row>
<returnvalue>setof anyelement, anyelement [, ... ]</returnvalue>
</para>
<para>
- Expands multiple arrays (possibly of different data types) to a set of
+ Expands multiple arrays (possibly of different data types) into a set of
rows. If the arrays are not all the same length then the shorter ones
- are padded with <literal>NULL</literal>s. This is only allowed in a
- query's FROM clause; see <xref linkend="queries-tablefunctions"/>.
+ are padded with <literal>NULL</literal>s. This form is only allowed
+ in a query's FROM clause; see <xref linkend="queries-tablefunctions"/>.
</para>
<para>
<literal>select * from unnest(ARRAY[1,2], ARRAY['foo','bar','baz']) as x(a,b)</literal>
result sets, but any function can be used.) This acts as
though the function's output were created as a temporary table for the
duration of this single <command>SELECT</command> command.
- When the optional <command>WITH ORDINALITY</command> clause is
- added to the function call, a new column is appended after
- all the function's output columns with numbering for each row.
+ If the function's result type is composite (including the case of a
+ function with multiple <literal>OUT</literal> parameters), each
+ attribute becomes a separate column in the implicit table.
+ </para>
+
+ <para>
+ When the optional <command>WITH ORDINALITY</command> clause is added
+ to the function call, an additional column of type <type>bigint</type>
+ will be appended to the function's result column(s). This column
+ numbers the rows of the function's result set, starting from 1.
+ By default, this column is named <literal>ordinality</literal>.
</para>
<para>
If an alias is written, a column
alias list can also be written to provide substitute names for
one or more attributes of the function's composite return
- type, including the column added by <literal>ORDINALITY</literal>
- if present.
+ type, including the ordinality column if present.
</para>
<para>