Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DC8AD9FBD66 for ; Thu, 25 Oct 2007 22:12:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 63351-09 for ; Thu, 25 Oct 2007 22:11:59 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from momjian.us (momjian.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id EC6F29F965A for ; Thu, 25 Oct 2007 22:11:57 -0300 (ADT) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id l9Q1Bwd24364 for pgsql-docs@postgresql.org; Thu, 25 Oct 2007 21:11:58 -0400 (EDT) From: Bruce Momjian Message-Id: <200710260111.l9Q1Bwd24364@momjian.us> Subject: Example of plpgsql RETURN NEXT To: PostgreSQL-documentation Date: Thu, 25 Oct 2007 21:11:58 -0400 (EDT) X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ELM1193361118-29407-0_" Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/99 X-Sequence-Number: 4520 --ELM1193361118-29407-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" 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. + --ELM1193361118-29407-0_ Content-Transfer-Encoding: 7bit Content-Type: text/x-diff Content-Disposition: inline; filename="/rtmp/diff" 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. ! --ELM1193361118-29407-0_--