Seems we never had an example in the documentation of plpgsql RETURN
NEXT. I got a submission from Ulrich Kroener and have applied it,
attached.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
Index: doc/src/sgml/plpgsql.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/plpgsql.sgml,v
retrieving revision 1.116
diff -c -c -r1.116 plpgsql.sgml
*** doc/src/sgml/plpgsql.sgml 25 Jul 2007 04:19:08 -0000 1.116
--- doc/src/sgml/plpgsql.sgml 26 Oct 2007 01:09:08 -0000
***************
*** 1411,1426 ****
</para>
<para>
! Functions that use <command>RETURN NEXT</command> or
! <command>RETURN QUERY</command> should be called in the
! following fashion:
<programlisting>
! SELECT * FROM some_func();
</programlisting>
! That is, the function must be used as a table source in a
! <literal>FROM</literal> clause.
</para>
<note>
--- 1411,1447 ----
</para>
<para>
! Here is an example of a function using <command>RETURN
! NEXT</command>:
<programlisting>
! CREATE TABLE foo (fooid INT, foosubid INT, fooname TEXT);
! INSERT INTO foo VALUES (1, 2, 'three');
! INSERT INTO foo VALUES (4, 5, 'six');
!
! CREATE OR REPLACE FUNCTION getAllFoo() RETURNS SETOF foo AS
! $BODY$
! DECLARE
! r foo%rowtype;
! BEGIN
! FOR r IN SELECT * FROM foo
! WHERE fooid > 0
! LOOP
! -- can do some processing here
! RETURN NEXT r; -- return next row of SELECT
! END LOOP;
! RETURN;
! END
! $BODY$
! LANGUAGE 'plpgsql' ;
!
! SELECT * FROM getallfoo();
</programlisting>
! Note that functions using <command>RETURN NEXT</command> or
! <command>RETURN QUERY</command> must be called as a table source in
! a <literal>FROM</literal> clause.
!
</para>
<note>