Change EXECUTE INTO to CREATE TABLE AS EXECUTE.
This commit is contained in:
parent
df08f5c003
commit
71e9f3b07f
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.13 2003/05/04 00:03:55 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.14 2003/07/01 00:04:31 petere Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -26,11 +26,12 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
<command>CREATE TABLE AS</command> creates a table and fills it
|
<command>CREATE TABLE AS</command> creates a table and fills it
|
||||||
with data computed by a <command>SELECT</command> command. The
|
with data computed by a <command>SELECT</command> command or an
|
||||||
table columns have the names and data types associated with the
|
<command>EXECUTE</command> that runs a prepared
|
||||||
output columns of the <command>SELECT</command> (except that you
|
<command>SELECT</command> command. The table columns have the
|
||||||
can override the column names by giving an explicit list of new
|
names and data types associated with the output columns of the
|
||||||
column names).
|
<command>SELECT</command> (except that you can override the column
|
||||||
|
names by giving an explicit list of new column names).
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -73,7 +74,9 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
|
|||||||
<para>
|
<para>
|
||||||
The name of a column in the new table. If column names are not
|
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
|
provided, they are taken from the output column names of the
|
||||||
query.
|
query. If the table is created out of an
|
||||||
|
<command>EXECUTE</command> command, a column name list can
|
||||||
|
currently not be specified.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -82,10 +85,12 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
|
|||||||
<term><replaceable>query</replaceable></term>
|
<term><replaceable>query</replaceable></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
A query statement (that is, a <command>SELECT</command>
|
A query statement (that is, a <command>SELECT</command> command
|
||||||
command). Refer to
|
or an <command>EXECUTE</command> command that runs a prepared
|
||||||
<xref linkend="sql-select" endterm="sql-select-title">
|
<command>SELECT</command> command). Refer to <xref
|
||||||
for a description of the allowed syntax.
|
linkend="sql-select" endterm="sql-select-title"> or <xref
|
||||||
|
linkend="sql-execute" endterm="sql-execute-title">,
|
||||||
|
respectively, for a description of the allowed syntax.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -96,9 +101,11 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
|
|||||||
<title>Diagnostics</title>
|
<title>Diagnostics</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Refer to <xref linkend="sql-createtable" endterm="sql-createtable-title"> and
|
Refer to <xref linkend="sql-createtable"
|
||||||
<xref linkend="sql-select" endterm="sql-select-title">
|
endterm="sql-createtable-title">, <xref linkend="sql-select"
|
||||||
for a summary of possible output messages.
|
endterm="sql-select-title">, and <xref linkend="sql-execute"
|
||||||
|
endterm="sql-execute-title"> for a summary of possible output
|
||||||
|
messages.
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
@ -131,6 +138,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
|
|||||||
<simplelist type="inline">
|
<simplelist type="inline">
|
||||||
<member><xref linkend="sql-createtable" endterm="sql-createtable-title"></member>
|
<member><xref linkend="sql-createtable" endterm="sql-createtable-title"></member>
|
||||||
<member><xref linkend="sql-createview" endterm="sql-createview-title"></member>
|
<member><xref linkend="sql-createview" endterm="sql-createview-title"></member>
|
||||||
|
<member><xref linkend="sql-execute" endterm="sql-execute-title"></member>
|
||||||
<member><xref linkend="sql-select" endterm="sql-select-title"></member>
|
<member><xref linkend="sql-select" endterm="sql-select-title"></member>
|
||||||
<member><xref linkend="sql-selectinto" endterm="sql-selectinto-title"></member>
|
<member><xref linkend="sql-selectinto" endterm="sql-selectinto-title"></member>
|
||||||
</simplelist>
|
</simplelist>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/execute.sgml,v 1.4 2003/04/26 23:56:51 petere Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/execute.sgml,v 1.5 2003/07/01 00:04:31 petere Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ PostgreSQL documentation
|
|||||||
|
|
||||||
<refsynopsisdiv>
|
<refsynopsisdiv>
|
||||||
<synopsis>
|
<synopsis>
|
||||||
EXECUTE <replaceable class="PARAMETER">plan_name</replaceable> [ (<replaceable class="PARAMETER">parameter</replaceable> [, ...] ) ] [ INTO [ TEMPORARY | TEMP ] <replaceable class="PARAMETER">table</replaceable> ]
|
EXECUTE <replaceable class="PARAMETER">plan_name</replaceable> [ (<replaceable class="PARAMETER">parameter</replaceable> [, ...] ) ]
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</refsynopsisdiv>
|
</refsynopsisdiv>
|
||||||
|
|
||||||
@ -40,13 +40,6 @@ EXECUTE <replaceable class="PARAMETER">plan_name</replaceable> [ (<replaceable c
|
|||||||
name of a prepared statement must be unique within a database session.
|
name of a prepared statement must be unique within a database session.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
|
||||||
Like <command>SELECT INTO</command>, <command>EXECUTE</command> can
|
|
||||||
store the results of executing a query into a newly-created
|
|
||||||
table, by specifying an <literal>INTO</> clause. For more information on this behavior,
|
|
||||||
see <xref linkend="sql-selectinto" endterm="sql-selectinto-title">.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
For more information on the creation and usage of prepared statements,
|
For more information on the creation and usage of prepared statements,
|
||||||
see <xref linkend="sql-prepare" endterm="sql-prepare-title">.
|
see <xref linkend="sql-prepare" endterm="sql-prepare-title">.
|
||||||
@ -78,18 +71,6 @@ EXECUTE <replaceable class="PARAMETER">plan_name</replaceable> [ (<replaceable c
|
|||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
<term><replaceable class="PARAMETER">table</replaceable></term>
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
The name of the table in which to store the results of executing
|
|
||||||
the statement (if it is a <command>SELECT</command>). If no
|
|
||||||
table is specified, the results are returned to the client (as
|
|
||||||
normal).
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* Copyright (c) 2002-2003, PostgreSQL Global Development Group
|
* Copyright (c) 2002-2003, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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();
|
portal = CreateNewPortal();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For EXECUTE INTO, make a copy of the stored query so that we can
|
* For CREATE TABLE / AS EXECUTE, make a copy of the stored query
|
||||||
* modify its destination (yech, but INTO has always been ugly).
|
* so that we can modify its destination (yech, but this has
|
||||||
* For regular EXECUTE we can just use the stored query where it sits,
|
* always been ugly). For regular EXECUTE we can just use the
|
||||||
* since the executor is read-only.
|
* stored query where it sits, since the executor is read-only.
|
||||||
*/
|
*/
|
||||||
if (stmt->into)
|
if (stmt->into)
|
||||||
{
|
{
|
||||||
@ -159,10 +159,10 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest)
|
|||||||
qcontext = PortalGetHeapMemory(portal);
|
qcontext = PortalGetHeapMemory(portal);
|
||||||
|
|
||||||
if (length(query_list) != 1)
|
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);
|
query = (Query *) lfirst(query_list);
|
||||||
if (query->commandType != CMD_SELECT)
|
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);
|
query->into = copyObject(stmt->into);
|
||||||
|
|
||||||
MemoryContextSwitchTo(oldContext);
|
MemoryContextSwitchTo(oldContext);
|
||||||
@ -519,7 +519,7 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate)
|
|||||||
if (execstmt->into)
|
if (execstmt->into)
|
||||||
{
|
{
|
||||||
if (query->commandType != CMD_SELECT)
|
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 */
|
/* Copy the query so we can modify it */
|
||||||
query = copyObject(query);
|
query = copyObject(query);
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
@ -4116,17 +4116,29 @@ PreparableStmt:
|
|||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* QUERY:
|
* EXECUTE <plan_name> [(params, ...)]
|
||||||
* EXECUTE <plan_name> [(params, ...)] [INTO ...]
|
* 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);
|
ExecuteStmt *n = makeNode(ExecuteStmt);
|
||||||
n->name = $2;
|
n->name = $2;
|
||||||
n->params = $3;
|
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;
|
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;
|
$$ = (Node *) n;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -80,10 +80,10 @@ ERROR: Parameter $3 of type boolean cannot be coerced into the expected type do
|
|||||||
-- invalid type
|
-- invalid type
|
||||||
PREPARE q4(nonexistenttype) AS SELECT $1;
|
PREPARE q4(nonexistenttype) AS SELECT $1;
|
||||||
ERROR: Type "nonexistenttype" does not exist
|
ERROR: Type "nonexistenttype" does not exist
|
||||||
-- execute into
|
-- create table as execute
|
||||||
PREPARE q5(int, text) AS
|
PREPARE q5(int, text) AS
|
||||||
SELECT * FROM tenk1 WHERE unique1 = $1 OR stringu1 = $2;
|
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;
|
SELECT * FROM q5_prep_results;
|
||||||
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
||||||
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
||||||
|
@ -38,8 +38,8 @@ EXECUTE q3(5::smallint, 10.5::float, false, 500::oid, 4::bigint, 'bytea');
|
|||||||
-- invalid type
|
-- invalid type
|
||||||
PREPARE q4(nonexistenttype) AS SELECT $1;
|
PREPARE q4(nonexistenttype) AS SELECT $1;
|
||||||
|
|
||||||
-- execute into
|
-- create table as execute
|
||||||
PREPARE q5(int, text) AS
|
PREPARE q5(int, text) AS
|
||||||
SELECT * FROM tenk1 WHERE unique1 = $1 OR stringu1 = $2;
|
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;
|
SELECT * FROM q5_prep_results;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user