From c6722d7211166c24e876df6f9b45d080622838c9 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 10 Nov 2007 20:14:36 +0000 Subject: [PATCH] Add an example of a SQL function with output parameters returning 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 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 0b8860c0c2..efee5d8d46 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -1,4 +1,4 @@ - + User-Defined Functions @@ -661,6 +661,22 @@ SELECT * FROM getfoo(1) AS t1; + + It is also possible to return multiple rows with the columns defined by + output parameters, like this: + + +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; + + + The key point here is that you must write 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 record. + + Currently, functions returning sets can also be called in the select list of a query. For each row that the query