From: Bruce Momjian <bruce@momjian.us>
To: PostgreSQL-documentation <pgsql-docs@postgresql.org>
Subject: Example of plpgsql RETURN NEXT
Date: Thu, 25 Oct 2007 21:11:58 -0400 (EDT)
Message-ID: <200710260111.l9Q1Bwd24364@momjian.us> (raw)
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. +
Attachments:/rtmp/diff (text/x-diff, 1.6K) download
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>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-docs@postgresql.org
Cc: bruce@momjian.us
Subject: Re: Example of plpgsql RETURN NEXT
In-Reply-To: <200710260111.l9Q1Bwd24364@momjian.us>
References: <200710260111.l9Q1Bwd24364@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox