Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bfda0a0

Browse files
committed
Doc: improve documentation for UNNEST().
Per a user question, spell out that UNNEST() returns array elements in storage order; also provide an example to clarify the behavior for multi-dimensional arrays. While here, also clarify the SELECT reference page's description of WITH ORDINALITY. These details were already given in 7.2.1.4, but a reference page should not omit details. Back-patch to v13; there's not room in the table in older versions. Discussion: https://postgr.es/m/FF1FB31F-0507-4F18-9559-2DE6E07E3B43@gmail.com
1 parent 2378d92 commit bfda0a0

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

doc/src/sgml/func.sgml

+15-4
Original file line numberDiff line numberDiff line change
@@ -17926,14 +17926,25 @@ SELECT NULLIF(value, '(none)') ...
1792617926
<returnvalue>setof anyelement</returnvalue>
1792717927
</para>
1792817928
<para>
17929-
Expands an array to a set of rows.
17929+
Expands an array into a set of rows.
17930+
The array's elements are read out in storage order.
1793017931
</para>
1793117932
<para>
1793217933
<literal>unnest(ARRAY[1,2])</literal>
1793317934
<returnvalue></returnvalue>
1793417935
<programlisting>
1793517936
1
1793617937
2
17938+
</programlisting>
17939+
</para>
17940+
<para>
17941+
<literal>unnest(ARRAY[['foo','bar'],['baz','quux']])</literal>
17942+
<returnvalue></returnvalue>
17943+
<programlisting>
17944+
foo
17945+
bar
17946+
baz
17947+
quux
1793717948
</programlisting>
1793817949
</para></entry>
1793917950
</row>
@@ -17944,10 +17955,10 @@ SELECT NULLIF(value, '(none)') ...
1794417955
<returnvalue>setof anyelement, anyelement [, ... ]</returnvalue>
1794517956
</para>
1794617957
<para>
17947-
Expands multiple arrays (possibly of different data types) to a set of
17958+
Expands multiple arrays (possibly of different data types) into a set of
1794817959
rows. If the arrays are not all the same length then the shorter ones
17949-
are padded with <literal>NULL</literal>s. This is only allowed in a
17950-
query's FROM clause; see <xref linkend="queries-tablefunctions"/>.
17960+
are padded with <literal>NULL</literal>s. This form is only allowed
17961+
in a query's FROM clause; see <xref linkend="queries-tablefunctions"/>.
1795117962
</para>
1795217963
<para>
1795317964
<literal>select * from unnest(ARRAY[1,2], ARRAY['foo','bar','baz']) as x(a,b)</literal>

doc/src/sgml/ref/select.sgml

+12-5
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,25 @@ TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ]
476476
result sets, but any function can be used.) This acts as
477477
though the function's output were created as a temporary table for the
478478
duration of this single <command>SELECT</command> command.
479-
When the optional <command>WITH ORDINALITY</command> clause is
480-
added to the function call, a new column is appended after
481-
all the function's output columns with numbering for each row.
479+
If the function's result type is composite (including the case of a
480+
function with multiple <literal>OUT</literal> parameters), each
481+
attribute becomes a separate column in the implicit table.
482+
</para>
483+
484+
<para>
485+
When the optional <command>WITH ORDINALITY</command> clause is added
486+
to the function call, an additional column of type <type>bigint</type>
487+
will be appended to the function's result column(s). This column
488+
numbers the rows of the function's result set, starting from 1.
489+
By default, this column is named <literal>ordinality</literal>.
482490
</para>
483491

484492
<para>
485493
An alias can be provided in the same way as for a table.
486494
If an alias is written, a column
487495
alias list can also be written to provide substitute names for
488496
one or more attributes of the function's composite return
489-
type, including the column added by <literal>ORDINALITY</literal>
490-
if present.
497+
type, including the ordinality column if present.
491498
</para>
492499

493500
<para>

0 commit comments

Comments
 (0)