Change EXECUTE INTO to CREATE TABLE AS EXECUTE.
authorPeter Eisentraut
Tue, 1 Jul 2003 00:04:31 +0000 (00:04 +0000)
committerPeter Eisentraut
Tue, 1 Jul 2003 00:04:31 +0000 (00:04 +0000)
doc/src/sgml/ref/create_table_as.sgml
doc/src/sgml/ref/execute.sgml
src/backend/commands/prepare.c
src/backend/parser/gram.y
src/test/regress/expected/prepare.out
src/test/regress/sql/prepare.sql

index d298e1a5ea1d622d83d0ad2238520413b843c6b3..0f648d56b3a93ca864d9111fb8993bf2f9ca077a 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -26,11 +26,12 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name
 
   
    CREATE TABLE AS creates a table and fills it
-   with data computed by a SELECT command.  The
-   table columns have the names and data types associated with the
-   output columns of the SELECT (except that you
-   can override the column names by giving an explicit list of new
-   column names).
+   with data computed by a SELECT command or an
+   EXECUTE that runs a prepared
+   SELECT command.  The table columns have the
+   names and data types associated with the output columns of the
+   SELECT (except that you can override the column
+   names by giving an explicit list of new column names).
   
 
   
@@ -73,7 +74,9 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name
      
       The name of a column in the new table.  If column names are not
       provided, they are taken from the output column names of the
-      query.
+      query.  If the table is created out of an
+      EXECUTE command, a column name list can
+      currently not be specified.
      
     
    
@@ -82,10 +85,12 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name
     query
     
      
-      A query statement (that is, a SELECT
-      command).  Refer to
-      
-      for a description of the allowed syntax.
+      A query statement (that is, a SELECT command
+      or an EXECUTE command that runs a prepared
+      SELECT command).  Refer to 
+      linkend="sql-select" endterm="sql-select-title"> or 
+      linkend="sql-execute" endterm="sql-execute-title">,
+      respectively, for a description of the allowed syntax.
      
     
    
@@ -96,9 +101,11 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name
   Diagnostics
 
   
-   Refer to  and
-   
-   for a summary of possible output messages.
+   Refer to 
+   endterm="sql-createtable-title">, 
+   endterm="sql-select-title">, and 
+   endterm="sql-execute-title"> for a summary of possible output
+   messages.
   
  
 
@@ -131,6 +138,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name
   
    
    
+   
    
    
   
index f4b0a062fc8e0400c37bf7b5aeedc56c1f83fd0b..7704b8ce27b67ade824d66ced73b88eca1c8dfeb 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -16,7 +16,7 @@ PostgreSQL documentation
 
  
 
-EXECUTE plan_name [ (parameter [, ...] ) ] [ INTO [ TEMPORARY | TEMP ] table ]
+EXECUTE plan_name [ (parameter [, ...] ) ]
 
  
 
@@ -40,13 +40,6 @@ EXECUTE plan_name [ (
    name of a prepared statement must be unique within a database session.
   
 
-  
-   Like SELECT INTOEXECUTE can
-   store the results of executing a query into a newly-created
-   table, by specifying an INTO clause. For more information on this behavior,
-   see .
-  
-
   
    For more information on the creation and usage of prepared statements,
    see .
@@ -78,18 +71,6 @@ EXECUTE plan_name [ (
      
     
    
-
-   
-    table
-    
-     
-      The name of the table in which to store the results of executing
-      the statement (if it is a SELECT). If no
-      table is specified, the results are returned to the client (as
-      normal).
-     
-    
-   
   
  
 
index 433fd8e049e86a7a4c8419ac43a2385c6c40f981..dad1b7f703c6cff910aa0ba0bb83be8cc4cfdd95 100644 (file)
@@ -10,7 +10,7 @@
  * Copyright (c) 2002-2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.18 2003/05/08 18:16:36 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.19 2003/07/01 00:04:31 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -140,10 +140,10 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest)
    portal = CreateNewPortal();
 
    /*
-    * For EXECUTE INTO, make a copy of the stored query so that we can
-    * modify its destination (yech, but INTO has always been ugly).
-    * For regular EXECUTE we can just use the stored query where it sits,
-    * since the executor is read-only.
+    * For CREATE TABLE / AS EXECUTE, make a copy of the stored query
+    * so that we can modify its destination (yech, but this has
+    * always been ugly).  For regular EXECUTE we can just use the
+    * stored query where it sits, since the executor is read-only.
     */
    if (stmt->into)
    {
@@ -159,10 +159,10 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest)
        qcontext = PortalGetHeapMemory(portal);
 
        if (length(query_list) != 1)
-           elog(ERROR, "INTO clause specified for non-SELECT query");
+           elog(ERROR, "prepared statement is not a SELECT");
        query = (Query *) lfirst(query_list);
        if (query->commandType != CMD_SELECT)
-           elog(ERROR, "INTO clause specified for non-SELECT query");
+           elog(ERROR, "prepared statement is not a SELECT");
        query->into = copyObject(stmt->into);
 
        MemoryContextSwitchTo(oldContext);
@@ -519,7 +519,7 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate)
            if (execstmt->into)
            {
                if (query->commandType != CMD_SELECT)
-                   elog(ERROR, "INTO clause specified for non-SELECT query");
+                   elog(ERROR, "prepared statement is not a SELECT");
 
                /* Copy the query so we can modify it */
                query = copyObject(query);
index a8df7c65e9dfe376d82464e09cc0c41ff7dc4426..fbd70807dff039c05a6b73d115d2984f8bb13450 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.423 2003/06/29 00:33:43 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.424 2003/07/01 00:04:31 petere Exp $
  *
  * HISTORY
  *   AUTHOR            DATE            MAJOR EVENT
@@ -4116,17 +4116,29 @@ PreparableStmt:
 
 /*****************************************************************************
  *
- *     QUERY:
- *             EXECUTE  [(params, ...)] [INTO ...]
+ * EXECUTE  [(params, ...)]
+ * CREATE TABLE  AS EXECUTE  [(params, ...)]
  *
  *****************************************************************************/
 
-ExecuteStmt: EXECUTE name execute_param_clause into_clause
+ExecuteStmt: EXECUTE name execute_param_clause
                {
                    ExecuteStmt *n = makeNode(ExecuteStmt);
                    n->name = $2;
                    n->params = $3;
+                   n->into = NULL;
+                   $$ = (Node *) n;
+               }
+           | CREATE OptTemp TABLE qualified_name OptCreateAs AS EXECUTE name execute_param_clause
+               {
+                   ExecuteStmt *n = makeNode(ExecuteStmt);
+                   n->name = $8;
+                   n->params = $9;
+                   $4->istemp = $2;
                    n->into = $4;
+                   if ($5)
+                       elog(ERROR, "column name list not allowed in CREATE TABLE / AS EXECUTE");
+                   /* ... because it's not implemented, but it could be */
                    $$ = (Node *) n;
                }
        ;
index 629e444fb7b7fbce78823dc9ac5865dfb78744dd..04ab65b718ff982e9459ce3ff3543f9a0cb18e72 100644 (file)
@@ -80,10 +80,10 @@ ERROR:  Parameter $3 of type boolean cannot be coerced into the expected type do
 -- invalid type
 PREPARE q4(nonexistenttype) AS SELECT $1;
 ERROR:  Type "nonexistenttype" does not exist
--- execute into
+-- create table as execute
 PREPARE q5(int, text) AS
    SELECT * FROM tenk1 WHERE unique1 = $1 OR stringu1 = $2;
-EXECUTE q5(200, 'DTAAAA') INTO TEMPORARY q5_prep_results;
+CREATE TEMPORARY TABLE q5_prep_results AS EXECUTE q5(200, 'DTAAAA');
 SELECT * FROM q5_prep_results;
  unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
 ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
index ee8df42e0e1b74cbd71f895285e72715335afa98..fc6924307da9f79c9fe5b52e408ff37b02ec4609 100644 (file)
@@ -38,8 +38,8 @@ EXECUTE q3(5::smallint, 10.5::float, false, 500::oid, 4::bigint, 'bytea');
 -- invalid type
 PREPARE q4(nonexistenttype) AS SELECT $1;
 
--- execute into
+-- create table as execute
 PREPARE q5(int, text) AS
    SELECT * FROM tenk1 WHERE unique1 = $1 OR stringu1 = $2;
-EXECUTE q5(200, 'DTAAAA') INTO TEMPORARY q5_prep_results;
+CREATE TEMPORARY TABLE q5_prep_results AS EXECUTE q5(200, 'DTAAAA');
 SELECT * FROM q5_prep_results;