Add an example of a SQL function with output parameters returning
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 10 Nov 2007 20:14:36 +0000 (20:14 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 10 Nov 2007 20:14:36 +0000 (20:14 +0000)
multiple rows.  I had thought this case was covered, but there was
no example in the obvious section to look in.

doc/src/sgml/xfunc.sgml

index 2c9ab245c5efde23107bb25121a7eeb25b90bc3e..8322a6da7401c8ff900cf58c4809f3d1a6bcd475 100644 (file)
@@ -661,6 +661,22 @@ SELECT * FROM getfoo(1) AS t1;
 </screen>
     </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