aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-11-10 20:14:36 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-11-10 20:14:36 +0000
commitc6722d7211166c24e876df6f9b45d080622838c9 (patch)
treee6da9743d56bacde3300c2927701343a2cadf917
parent2b477a2c7344bed9223e2bc38dbfbf8590ae85a2 (diff)
downloadpostgresql-c6722d7211166c24e876df6f9b45d080622838c9.tar.gz
postgresql-c6722d7211166c24e876df6f9b45d080622838c9.zip
Add an example of a SQL function with output parameters returning
multiple rows. I had thought this case was covered, but there was no example in the obvious section to look in.
-rw-r--r--doc/src/sgml/xfunc.sgml18
1 files changed, 17 insertions, 1 deletions
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index 0b8860c0c29..efee5d8d469 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.129 2007/06/26 22:05:04 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.130 2007/11/10 20:14:36 tgl Exp $ -->
<sect1 id="xfunc">
<title>User-Defined Functions</title>
@@ -662,6 +662,22 @@ SELECT * FROM getfoo(1) AS t1;
</para>
<para>
+ It is also possible to return multiple rows with the columns defined by
+ output parameters, like this:
+
+<programlisting>
+CREATE FUNCTION sum_n_product_with_tab (x int, OUT sum int, OUT product int) RETURNS SETOF record AS $$
+ SELECT x + tab.y, x * tab.y FROM tab;
+$$ LANGUAGE SQL;
+</programlisting>
+
+ The key point here is that you must write <literal>RETURNS SETOF record</>
+ to indicate that the function returns multiple rows instead of just one.
+ If there is only one output parameter, write that parameter's type
+ instead of <type>record</>.
+ </para>
+
+ <para>
Currently, functions returning sets can also be called in the select list
of a query. For each row that the query
generates by itself, the function returning set is invoked, and an output