summaryrefslogtreecommitdiff
path: root/doc/src/sgml/plpgsql.sgml
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-08-12 20:05:56 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-08-12 20:05:56 +0000
commit3f8db37c2f1eeeffd9dae3189b783a463f56fe77 (patch)
treef6520123161af6191b5f53262d67eab69b24eccf /doc/src/sgml/plpgsql.sgml
parent883f4b42d7292f1a7142e55046cee86f92049b5a (diff)
Tweak SPI_cursor_open to allow INSERT/UPDATE/DELETE RETURNING; this was
merely a matter of fixing the error check, since the underlying Portal infrastructure already handles it. This in turn allows these statements to be used in some existing plpgsql and plperl contexts, such as a plpgsql FOR loop. Also, do some marginal code cleanup in places that were being sloppy about distinguishing SELECT from SELECT INTO.
Diffstat (limited to 'doc/src/sgml/plpgsql.sgml')
-rw-r--r--doc/src/sgml/plpgsql.sgml27
1 files changed, 17 insertions, 10 deletions
diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml
index ac5b2b4cfc6..fb2fe735a6c 100644
--- a/doc/src/sgml/plpgsql.sgml
+++ b/doc/src/sgml/plpgsql.sgml
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.97 2006/06/16 23:29:26 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.98 2006/08/12 20:05:54 tgl Exp $ -->
<chapter id="plpgsql">
<title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
@@ -2040,9 +2040,8 @@ END LOOP <optional> <replaceable>label</replaceable> </optional>;
The <replaceable>target</replaceable> is a record variable, row variable,
or comma-separated list of scalar variables.
The <replaceable>target</replaceable> is successively assigned each row
- resulting from the <replaceable>query</replaceable> (which must be a
- <command>SELECT</command> command) and the loop body is executed for each
- row. Here is an example:
+ resulting from the <replaceable>query</replaceable> and the loop body is
+ executed for each row. Here is an example:
<programlisting>
CREATE FUNCTION cs_refresh_mviews() RETURNS integer AS $$
DECLARE
@@ -2070,6 +2069,15 @@ $$ LANGUAGE plpgsql;
</para>
<para>
+ The <replaceable>query</replaceable> used in this type of <literal>FOR</>
+ statement can be any query that returns rows to the caller:
+ <command>SELECT</> (without <literal>INTO</>) is the most common case,
+ but you can also use <command>INSERT</>, <command>UPDATE</>, or
+ <command>DELETE</> with a <literal>RETURNING</> clause. Some utility
+ commands such as <command>EXPLAIN</> will work too.
+ </para>
+
+ <para>
The <literal>FOR-IN-EXECUTE</> statement is another way to iterate over
rows:
<synopsis>
@@ -2078,12 +2086,11 @@ FOR <replaceable>target</replaceable> IN EXECUTE <replaceable>text_expression</r
<replaceable>statements</replaceable>
END LOOP <optional> <replaceable>label</replaceable> </optional>;
</synopsis>
- This is like the previous form, except that the source
- <command>SELECT</command> statement is specified as a string
- expression, which is evaluated and replanned on each entry to
- the <literal>FOR</> loop. This allows the programmer to choose the speed of
- a preplanned query or the flexibility of a dynamic query, just
- as with a plain <command>EXECUTE</command> statement.
+ This is like the previous form, except that the source query
+ is specified as a string expression, which is evaluated and replanned
+ on each entry to the <literal>FOR</> loop. This allows the programmer to
+ choose the speed of a preplanned query or the flexibility of a dynamic
+ query, just as with a plain <command>EXECUTE</command> statement.
</para>
<note>