Skip to content

Commit fa9eb31

Browse files
committed
Add plpgsql doc example of RETURN NEXT.
Ulrich Kroener
1 parent 48c16e1 commit fa9eb31

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

doc/src/sgml/plpgsql.sgml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.116 2007/07/25 04:19:08 neilc Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.117 2007/10/26 01:11:09 momjian Exp $ -->
22

33
<chapter id="plpgsql">
44
<title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
@@ -1411,16 +1411,37 @@ RETURN QUERY <replaceable>query</replaceable>;
14111411
</para>
14121412

14131413
<para>
1414-
Functions that use <command>RETURN NEXT</command> or
1415-
<command>RETURN QUERY</command> should be called in the
1416-
following fashion:
1414+
Here is an example of a function using <command>RETURN
1415+
NEXT</command>:
14171416

14181417
<programlisting>
1419-
SELECT * FROM some_func();
1418+
CREATE TABLE foo (fooid INT, foosubid INT, fooname TEXT);
1419+
INSERT INTO foo VALUES (1, 2, 'three');
1420+
INSERT INTO foo VALUES (4, 5, 'six');
1421+
1422+
CREATE OR REPLACE FUNCTION getAllFoo() RETURNS SETOF foo AS
1423+
$BODY$
1424+
DECLARE
1425+
r foo%rowtype;
1426+
BEGIN
1427+
FOR r IN SELECT * FROM foo
1428+
WHERE fooid &gt; 0
1429+
LOOP
1430+
-- can do some processing here
1431+
RETURN NEXT r; -- return next row of SELECT
1432+
END LOOP;
1433+
RETURN;
1434+
END
1435+
$BODY$
1436+
LANGUAGE 'plpgsql' ;
1437+
1438+
SELECT * FROM getallfoo();
14201439
</programlisting>
14211440

1422-
That is, the function must be used as a table source in a
1423-
<literal>FROM</literal> clause.
1441+
Note that functions using <command>RETURN NEXT</command> or
1442+
<command>RETURN QUERY</command> must be called as a table source in
1443+
a <literal>FROM</literal> clause.
1444+
14241445
</para>
14251446

14261447
<note>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy