Add table creation and population to example
authorPeter Eisentraut
Mon, 26 Jul 2010 20:14:06 +0000 (20:14 +0000)
committerPeter Eisentraut
Mon, 26 Jul 2010 20:14:06 +0000 (20:14 +0000)
from John Gage

doc/src/sgml/xfunc.sgml

index e728eb3064053237356028b14a63ed9912a5ddd3..a4dafa0c638be2f8470b4353ca893bb62baa811b 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
  
   User-Defined Functions
@@ -861,10 +861,23 @@ SELECT * FROM getfoo(1) AS t1;
      output parameters, like this:
 
 
+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)
 
 
      The key point here is that you must write RETURNS SETOF record