diff options
Diffstat (limited to 'doc/src/sgml/func.sgml')
-rw-r--r-- | doc/src/sgml/func.sgml | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 528197e4bcc..34c5c2a2d6b 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -13278,7 +13278,7 @@ select $1[i][j] generate_subscripts($1,2) g2(j); $$ LANGUAGE sql IMMUTABLE; CREATE FUNCTION -postgres=# SELECT * FROM unnest2(ARRAY[[1,2],[3,4]]); +SELECT * FROM unnest2(ARRAY[[1,2],[3,4]]); unnest2 --------- 1 @@ -13289,6 +13289,48 @@ postgres=# SELECT * FROM unnest2(ARRAY[[1,2],[3,4]]); </programlisting> </para> + <indexterm> + <primary>ordinality</primary> + </indexterm> + + <para> + When a function in the <literal>FROM</literal> clause is suffixed by + <literal>WITH ORDINALITY</literal>, a <type>bigint</type> column is appended + to the output which starts from 1 and increments by 1 for each row of the + function's output. This is most useful in the case of set returning functions + such as UNNEST(). This functionality is available for functions returning + composite types or using <literal>OUT</literal> parameters, but not when using + a function returning <literal>RECORD</literal> with an explicit column + definition list. + +<programlisting> +-- set returning function WITH ORDINALITY +SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n); + ls | n +-----------------+---- + pg_serial | 1 + pg_twophase | 2 + postmaster.opts | 3 + pg_notify | 4 + postgresql.conf | 5 + pg_tblspc | 6 + logfile | 7 + base | 8 + postmaster.pid | 9 + pg_ident.conf | 10 + global | 11 + pg_clog | 12 + pg_snapshots | 13 + pg_multixact | 14 + PG_VERSION | 15 + pg_xlog | 16 + pg_hba.conf | 17 + pg_stat_tmp | 18 + pg_subtrans | 19 +(19 rows) +</programlisting> + </para> + </sect1> <sect1 id="functions-info"> |