|
1 |
| -<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.150 2010/07/25 08:30:42 petere Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.151 2010/07/26 20:14:05 petere Exp $ --> |
2 | 2 |
|
3 | 3 | <sect1 id="xfunc">
|
4 | 4 | <title>User-Defined Functions</title>
|
@@ -861,10 +861,23 @@ SELECT * FROM getfoo(1) AS t1;
|
861 | 861 | output parameters, like this:
|
862 | 862 |
|
863 | 863 | <programlisting>
|
| 864 | +CREATE TABLE tab (y int, z int); |
| 865 | +INSERT INTO tab VALUES (1, 2), (3, 4), (5, 6), (7, 8); |
| 866 | + |
864 | 867 | CREATE FUNCTION sum_n_product_with_tab (x int, OUT sum int, OUT product int)
|
865 |
| -RETURNS SETOF record AS $$ |
| 868 | +RETURNS SETOF record |
| 869 | +AS $$ |
866 | 870 | SELECT $1 + tab.y, $1 * tab.y FROM tab;
|
867 | 871 | $$ LANGUAGE SQL;
|
| 872 | + |
| 873 | +SELECT * FROM sum_n_product_with_tab(10); |
| 874 | + sum | product |
| 875 | +-----+--------- |
| 876 | + 11 | 10 |
| 877 | + 13 | 30 |
| 878 | + 15 | 50 |
| 879 | + 17 | 70 |
| 880 | +(4 rows) |
868 | 881 | </programlisting>
|
869 | 882 |
|
870 | 883 | The key point here is that you must write <literal>RETURNS SETOF record</>
|
|