From 3f8db37c2f1eeeffd9dae3189b783a463f56fe77 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 12 Aug 2006 20:05:56 +0000 Subject: 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. --- doc/src/sgml/plpgsql.sgml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'doc/src/sgml/plpgsql.sgml') 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 @@ - + <application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language @@ -2040,9 +2040,8 @@ END LOOP label ; The target is a record variable, row variable, or comma-separated list of scalar variables. The target is successively assigned each row - resulting from the query (which must be a - SELECT command) and the loop body is executed for each - row. Here is an example: + resulting from the query and the loop body is + executed for each row. Here is an example: CREATE FUNCTION cs_refresh_mviews() RETURNS integer AS $$ DECLARE @@ -2069,6 +2068,15 @@ $$ LANGUAGE plpgsql; assigned row value is still accessible after the loop. + + The query used in this type of FOR + statement can be any query that returns rows to the caller: + SELECT (without INTO) is the most common case, + but you can also use INSERT, UPDATE, or + DELETE with a RETURNING clause. Some utility + commands such as EXPLAIN will work too. + + The FOR-IN-EXECUTE statement is another way to iterate over rows: @@ -2078,12 +2086,11 @@ FOR target IN EXECUTE text_expressionstatements END LOOP label ; - This is like the previous form, except that the source - SELECT statement is specified as a string - expression, which is evaluated and replanned on each entry to - the 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 EXECUTE 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 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 EXECUTE statement. -- cgit v1.2.3