Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 662affc

Browse filesBrowse 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 1f113ab commit 662affc
Copy full SHA for 662affc

File tree

Expand file treeCollapse file tree

2 files changed

+27
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-9
lines changed

‎doc/src/sgml/func.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/func.sgml
+15-4Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17905,14 +17905,25 @@ SELECT NULLIF(value, '(none)') ...
1790517905
<returnvalue>setof anyelement</returnvalue>
1790617906
</para>
1790717907
<para>
17908-
Expands an array to a set of rows.
17908+
Expands an array into a set of rows.
17909+
The array's elements are read out in storage order.
1790917910
</para>
1791017911
<para>
1791117912
<literal>unnest(ARRAY[1,2])</literal>
1791217913
<returnvalue></returnvalue>
1791317914
<programlisting>
1791417915
1
1791517916
2
17917+
</programlisting>
17918+
</para>
17919+
<para>
17920+
<literal>unnest(ARRAY[['foo','bar'],['baz','quux']])</literal>
17921+
<returnvalue></returnvalue>
17922+
<programlisting>
17923+
foo
17924+
bar
17925+
baz
17926+
quux
1791617927
</programlisting>
1791717928
</para></entry>
1791817929
</row>
@@ -17923,10 +17934,10 @@ SELECT NULLIF(value, '(none)') ...
1792317934
<returnvalue>setof anyelement, anyelement [, ... ]</returnvalue>
1792417935
</para>
1792517936
<para>
17926-
Expands multiple arrays (possibly of different data types) to a set of
17937+
Expands multiple arrays (possibly of different data types) into a set of
1792717938
rows. If the arrays are not all the same length then the shorter ones
17928-
are padded with <literal>NULL</literal>s. This is only allowed in a
17929-
query's FROM clause; see <xref linkend="queries-tablefunctions"/>.
17939+
are padded with <literal>NULL</literal>s. This form is only allowed
17940+
in a query's FROM clause; see <xref linkend="queries-tablefunctions"/>.
1793017941
</para>
1793117942
<para>
1793217943
<literal>select * from unnest(ARRAY[1,2], ARRAY['foo','bar','baz']) as x(a,b)</literal>

‎doc/src/sgml/ref/select.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/ref/select.sgml
+12-5Lines changed: 12 additions & 5 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.