Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc6722d7

Browse files
committed
Add an example of a SQL function with output parameters returning
multiple rows. I had thought this case was covered, but there wasno example in the obvious section to look in.
1 parent2b477a2 commitc6722d7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎doc/src/sgml/xfunc.sgml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 $ -->
22

33
<sect1 id="xfunc">
44
<title>User-Defined Functions</title>
@@ -661,6 +661,22 @@ SELECT * FROM getfoo(1) AS t1;
661661
</screen>
662662
</para>
663663

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+
664680
<para>
665681
Currently, functions returning sets can also be called in the select list
666682
of a query. For each row that the query

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp