|
1 |
| -<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.129 2007/06/26 22:05:04 tgl Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.130 2007/11/10 20:14:36 tgl Exp $ --> |
2 | 2 |
|
3 | 3 | <sect1 id="xfunc">
|
4 | 4 | <title>User-Defined Functions</title>
|
@@ -661,6 +661,22 @@ SELECT * FROM getfoo(1) AS t1;
|
661 | 661 | </screen>
|
662 | 662 | </para>
|
663 | 663 |
|
| 664 | + <para> |
| 665 | + It is also possible to return multiple rows with the columns defined by |
| 666 | + output parameters, like this: |
| 667 | + |
| 668 | +<programlisting> |
| 669 | +CREATE FUNCTION sum_n_product_with_tab (x int, OUT sum int, OUT product int) RETURNS SETOF record AS $$ |
| 670 | + SELECT x + tab.y, x * tab.y FROM tab; |
| 671 | +$$ LANGUAGE SQL; |
| 672 | +</programlisting> |
| 673 | + |
| 674 | + The key point here is that you must write <literal>RETURNS SETOF record</> |
| 675 | + to indicate that the function returns multiple rows instead of just one. |
| 676 | + If there is only one output parameter, write that parameter's type |
| 677 | + instead of <type>record</>. |
| 678 | + </para> |
| 679 | + |
664 | 680 | <para>
|
665 | 681 | Currently, functions returning sets can also be called in the select list
|
666 | 682 | of a query. For each row that the query
|
|