@@ -52,7 +52,8 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="parameter">expression</replac
5252 [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ] [ [ AS ] <replaceable class="parameter">alias</replaceable> [ ( <replaceable class="parameter">column_alias</replaceable> [, ...] ) ] ]
5353 [ LATERAL ] ( <replaceable class="parameter">select</replaceable> ) [ AS ] <replaceable class="parameter">alias</replaceable> [ ( <replaceable class="parameter">column_alias</replaceable> [, ...] ) ]
5454 <replaceable class="parameter">with_query_name</replaceable> [ [ AS ] <replaceable class="parameter">alias</replaceable> [ ( <replaceable class="parameter">column_alias</replaceable> [, ...] ) ] ]
55- [ LATERAL ] <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) [ AS ] <replaceable class="parameter">alias</replaceable> [ ( <replaceable class="parameter">column_alias</replaceable> [, ...] | <replaceable class="parameter">column_definition</replaceable> [, ...] ) ]
55+ [ LATERAL ] <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) [ WITH ORDINALITY ] [ [ AS ] <replaceable class="parameter">alias</replaceable> [ ( <replaceable class="parameter">column_alias</replaceable> [, ...] ) ] ]
56+ [ LATERAL ] <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) [ AS ] <replaceable class="parameter">alias</replaceable> ( <replaceable class="parameter">column_definition</replaceable> [, ...] )
5657 [ LATERAL ] <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) AS ( <replaceable class="parameter">column_definition</replaceable> [, ...] )
5758 <replaceable class="parameter">from_item</replaceable> [ NATURAL ] <replaceable class="parameter">join_type</replaceable> <replaceable class="parameter">from_item</replaceable> [ ON <replaceable class="parameter">join_condition</replaceable> | USING ( <replaceable class="parameter">join_column</replaceable> [, ...] ) ]
5859
@@ -368,18 +369,40 @@ TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ]
368369 clause. (This is especially useful for functions that return
369370 result sets, but any function can be used.) This acts as
370371 though its output were created as a temporary table for the
371- duration of this single <command>SELECT</command> command. An
372- alias can also be used. If an alias is written, a column alias
373- list can also be written to provide substitute names for one
374- or more attributes of the function's composite return type. If
375- the function has been defined as returning the <type>record</>
376- data type, then an alias or the key word <literal>AS</> must
377- be present, followed by a column definition list in the form
378- <literal>( <replaceable
372+ duration of this single <command>SELECT</command> command.
373+ When the optional <command>WITH ORDINALITY</command> is
374+ appended to the function call, a new column is appended after
375+ all the function call's columns with numbering for each row.
376+ For example:
377+ <programlisting>
378+ SELECT * FROM unnest(ARRAY['a','b','c','d','e','f']) WITH ORDINALITY;
379+ unnest | ordinality
380+ --------+----------
381+ a | 1
382+ b | 2
383+ c | 3
384+ d | 4
385+ e | 5
386+ f | 6
387+ (6 rows)
388+ </programlisting>
389+ An alias can also be used. If an alias is written, a column
390+ alias list can also be written to provide substitute names for
391+ one or more attributes of the function's composite return
392+ type, including the column added by <literal>ORDINALITY</literal>
393+ if present.
394+ </para>
395+
396+ <para>
397+ If the function has been defined as returning the
398+ <type>record</> data type, then an alias or the key word
399+ <literal>AS</> must be present, followed by a column
400+ definition list in the form <literal>( <replaceable
379401 class="parameter">column_name</replaceable> <replaceable
380- class="parameter">data_type</replaceable> <optional>, ... </>
381- )</literal>. The column definition list must match the actual
382- number and types of columns returned by the function.
402+ class="parameter">data_type</replaceable> <optional>, ...
403+ </>)</literal>. The column definition list must match the
404+ actual number and types of columns returned by the function.
405+ <literal>ORDINALITY</literal> does not work in this case.
383406 </para>
384407 </listitem>
385408 </varlistentry>
0 commit comments