Example of plpgsql RETURN NEXT
Example of plpgsql RETURN NEXT
От:
Bruce Momjian <bruce@momjian.us>
Дата:
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 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 ****
! Functions that use RETURN NEXT or
! RETURN QUERY should be called in the
! following fashion:
! SELECT * FROM some_func();
! That is, the function must be used as a table source in a
! FROM clause.
--- 1411,1447 ----
! Here is an example of a function using RETURN
! NEXT:
! 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();
! Note that functions using RETURN NEXT or
! RETURN QUERY must be called as a table source in
! a FROM clause.
!