diff options
Diffstat (limited to 'doc/src/sgml/plpgsql.sgml')
| -rw-r--r-- | doc/src/sgml/plpgsql.sgml | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index 42bd6048b6..e47142078c 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -1,4 +1,4 @@ -<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.132 2008/07/16 01:30:21 tgl Exp $ --> +<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.133 2008/07/18 03:32:51 tgl Exp $ --> <chapter id="plpgsql"> <title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title> @@ -157,6 +157,8 @@ parameters in place of an explicit specification of the return type. This does not add any fundamental capability to the language, but it is often convenient, especially for returning multiple values. + The <literal>RETURNS TABLE</> notation can also be used in place + of <literal>RETURNS SETOF</>. </para> <para> @@ -469,6 +471,23 @@ $$ LANGUAGE plpgsql; </para> <para> + Another way to declare a <application>PL/pgSQL</application> function + is with <literal>RETURNS TABLE</>, for example: + +<programlisting> +CREATE FUNCTION extended_sales(p_itemno int) RETURNS TABLE(quantity int, total numeric) AS $$ +BEGIN + RETURN QUERY SELECT quantity, quantity * price FROM sales WHERE itemno = p_itemno; +END; +$$ LANGUAGE plpgsql; +</programlisting> + + This is exactly equivalent to declaring one or more <literal>OUT</> + parameters and specifying <literal>RETURNS SETOF + <replaceable>sometype</></literal>. + </para> + + <para> When the return type of a <application>PL/pgSQL</application> function is declared as a polymorphic type (<type>anyelement</type>, <type>anyarray</type>, <type>anynonarray</type>, or <type>anyenum</>), |
