diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2003-07-01 00:04:31 +0000 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2003-07-01 00:04:31 +0000 |
commit | 71e9f3b07f2f993492233dc2fff0566acc70eb64 (patch) | |
tree | bf63ec576f78d03eeb72a181ac0d47554e695358 /src | |
parent | df08f5c0030590980a203b72cdfdba817ff95b30 (diff) | |
download | postgresql-71e9f3b07f2f993492233dc2fff0566acc70eb64.tar.gz postgresql-71e9f3b07f2f993492233dc2fff0566acc70eb64.zip |
Change EXECUTE INTO to CREATE TABLE AS EXECUTE.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/prepare.c | 16 | ||||
-rw-r--r-- | src/backend/parser/gram.y | 20 | ||||
-rw-r--r-- | src/test/regress/expected/prepare.out | 4 | ||||
-rw-r--r-- | src/test/regress/sql/prepare.sql | 4 |
4 files changed, 28 insertions, 16 deletions
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 433fd8e049e..dad1b7f703c 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -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); diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index a8df7c65e9d..fbd70807dff 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -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 <plan_name> [(params, ...)] [INTO ...] + * EXECUTE <plan_name> [(params, ...)] + * CREATE TABLE <name> AS EXECUTE <plan_name> [(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; } ; diff --git a/src/test/regress/expected/prepare.out b/src/test/regress/expected/prepare.out index 629e444fb7b..04ab65b718f 100644 --- a/src/test/regress/expected/prepare.out +++ b/src/test/regress/expected/prepare.out @@ -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 ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+--------- diff --git a/src/test/regress/sql/prepare.sql b/src/test/regress/sql/prepare.sql index ee8df42e0e1..fc6924307da 100644 --- a/src/test/regress/sql/prepare.sql +++ b/src/test/regress/sql/prepare.sql @@ -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; |