Commit b4d7ea5f authored by Peter Eisentraut's avatar Peter Eisentraut

Add table creation and population to example

from John Gage
parent d017f835
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.150 2010/07/25 08:30:42 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.151 2010/07/26 20:14:05 petere Exp $ -->
<sect1 id="xfunc">
<title>User-Defined Functions</title>
......@@ -861,10 +861,23 @@ SELECT * FROM getfoo(1) AS t1;
output parameters, like this:
<programlisting>
CREATE TABLE tab (y int, z int);
INSERT INTO tab VALUES (1, 2), (3, 4), (5, 6), (7, 8);
CREATE FUNCTION sum_n_product_with_tab (x int, OUT sum int, OUT product int)
RETURNS SETOF record AS $$
RETURNS SETOF record
AS $$
SELECT $1 + tab.y, $1 * tab.y FROM tab;
$$ LANGUAGE SQL;
SELECT * FROM sum_n_product_with_tab(10);
sum | product
-----+---------
11 | 10
13 | 30
15 | 50
17 | 70
(4 rows)
</programlisting>
The key point here is that you must write <literal>RETURNS SETOF record</>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment