summaryrefslogtreecommitdiff
path: root/doc/src/sgml/plpgsql.sgml
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-07-18 03:32:53 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-07-18 03:32:53 +0000
commit69a785b8bfe076847f72317a41964821e85ccfd6 (patch)
tree8089a0c1e3b1075d81f49a82ab73b443dbe7d564 /doc/src/sgml/plpgsql.sgml
parenta8fb90cf2db614f3c1d4331bfaafd9a1953148e9 (diff)
downloadpostgresql-69a785b8bfe076847f72317a41964821e85ccfd6.tar.gz
Implement SQL-spec RETURNS TABLE syntax for functions.
(Unlike the original submission, this patch treats TABLE output parameters as being entirely equivalent to OUT parameters -- tgl) Pavel Stehule
Diffstat (limited to 'doc/src/sgml/plpgsql.sgml')
-rw-r--r--doc/src/sgml/plpgsql.sgml21
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</>),