From c59887f91618b95f42a33d4c62dac35165a7910a Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Tue, 7 Jun 2005 02:47:23 +0000 Subject: Add support for an optional INTO clause to PL/PgSQL's EXECUTE command. This allows the result of executing a SELECT to be assigned to a row variable, record variable, or list of scalars. Docs and regression tests updated. Per Pavel Stehule, improvements and cleanup by Neil Conway. --- doc/src/sgml/plpgsql.sgml | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index 7d2b37e41d7..d96c123e21c 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -1,5 +1,5 @@ @@ -1251,13 +1251,14 @@ NULL; EXECUTE statement is provided: -EXECUTE command-string; +EXECUTE command-string [ INTO target ]; where command-string is an expression - yielding a string (of type - text) containing the command - to be executed. This string is fed literally to the SQL engine. + yielding a string (of type text) containing the + command to be executed and target is a + record variable, row variable, or a comma-separated list of + simple variables and record/row fields. @@ -1276,16 +1277,22 @@ EXECUTE command-string; - The results from SELECT commands are discarded - by EXECUTE, and SELECT INTO - is not currently supported within EXECUTE. - So there is no way to extract a result from a dynamically-created - SELECT using the plain EXECUTE - command. There are two other ways to do it, however: one is to use the - FOR-IN-EXECUTE - loop form described in , - and the other is to use a cursor with OPEN-FOR-EXECUTE, as - described in . + The INTO clause specifies where the results of + a SELECT command should be assigned. If a row + or variable list is provided, it must exactly match the structure + of the results produced by the SELECT (when a + record variable is used, it will configure itself to match the + result's structure automatically). If multiple rows are returned, + only the first will be assigned to the INTO + variable. If no rows are returned, NULL is assigned to the + INTO variable. If no INTO + clause is specified, the results of a SELECT + command are discarded. + + + + SELECT INTO is not currently supported within + EXECUTE. @@ -1364,7 +1371,7 @@ EXECUTE 'UPDATE tbl SET ' command, which has the form: -GET DIAGNOSTICS variable = item , ... ; +GET DIAGNOSTICS variable = item , ... ; This command allows retrieval of system status indicators. Each @@ -2173,7 +2180,7 @@ SELECT merge_db (1, 'dennis'); Another way is to use the cursor declaration syntax, which in general is: -name CURSOR ( arguments ) FOR query ; +name CURSOR ( arguments ) FOR query; (FOR may be replaced by IS for Oracle compatibility.) @@ -2218,7 +2225,7 @@ DECLARE <command>OPEN FOR</command> <replaceable>query</replaceable> -OPEN unbound_cursor FOR query ; +OPEN unbound_cursor FOR query; @@ -3188,7 +3195,7 @@ DECLARE func_body text; func_cmd text; BEGIN - func_body := 'BEGIN' ; + func_body := 'BEGIN'; -- Notice how we scan through the results of a query in a FOR loop -- using the FOR <record> construct. -- cgit v1.2.3