TABLE command
This commit is contained in:
parent
f179d5ea99
commit
b09a1a2942
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.39 2008/11/14 10:22:46 petere Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.40 2008/11/20 14:04:45 petere Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -196,10 +196,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 <xref linkend="sql-select" endterm="sql-select-title"> or
|
A <xref linkend="sql-select"
|
||||||
|
endterm="sql-select-title">, <link linkend="sql-table">TABLE</link>,
|
||||||
|
or
|
||||||
<xref linkend="sql-values" endterm="sql-values-title"> command,
|
<xref linkend="sql-values" endterm="sql-values-title"> command,
|
||||||
or an <xref linkend="sql-execute" endterm="sql-execute-title"> command
|
or an <xref linkend="sql-execute" endterm="sql-execute-title"> command
|
||||||
that runs a prepared <command>SELECT</> or <command>VALUES</> query.
|
that runs a prepared <command>SELECT</>, <command>TABLE</>, or <command>VALUES</> query.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -260,6 +262,16 @@ CREATE TABLE films_recent AS
|
|||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
To copy a table completely, the short form using
|
||||||
|
the <literal>TABLE</literal> command can also be used:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
CREATE TABLE films2 AS
|
||||||
|
TABLE films;
|
||||||
|
</programlisting>
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Create a new temporary table <literal>films_recent</literal>, consisting of
|
Create a new temporary table <literal>films_recent</literal>, consisting of
|
||||||
only recent entries from the table <literal>films</literal>, using a
|
only recent entries from the table <literal>films</literal>, using a
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.109 2008/11/19 12:21:57 petere Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.110 2008/11/20 14:04:45 petere Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -12,6 +12,7 @@ PostgreSQL documentation
|
|||||||
|
|
||||||
<refnamediv>
|
<refnamediv>
|
||||||
<refname>SELECT</refname>
|
<refname>SELECT</refname>
|
||||||
|
<refname>TABLE</refname>
|
||||||
<refname>WITH</refname>
|
<refname>WITH</refname>
|
||||||
<refpurpose>retrieve rows from a table or view</refpurpose>
|
<refpurpose>retrieve rows from a table or view</refpurpose>
|
||||||
</refnamediv>
|
</refnamediv>
|
||||||
@ -20,6 +21,10 @@ PostgreSQL documentation
|
|||||||
<primary>SELECT</primary>
|
<primary>SELECT</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
|
|
||||||
|
<indexterm zone="sql-select">
|
||||||
|
<primary>TABLE command</primary>
|
||||||
|
</indexterm>
|
||||||
|
|
||||||
<indexterm zone="sql-select">
|
<indexterm zone="sql-select">
|
||||||
<primary>WITH</primary>
|
<primary>WITH</primary>
|
||||||
<secondary>in SELECT</secondary>
|
<secondary>in SELECT</secondary>
|
||||||
@ -53,6 +58,8 @@ where <replaceable class="parameter">from_item</replaceable> can be one of:
|
|||||||
and <replaceable class="parameter">with_query</replaceable> is:
|
and <replaceable class="parameter">with_query</replaceable> is:
|
||||||
|
|
||||||
<replaceable class="parameter">with_query_name</replaceable> [ ( <replaceable class="parameter">column_name</replaceable> [, ...] ) ] AS ( <replaceable class="parameter">select</replaceable> )
|
<replaceable class="parameter">with_query_name</replaceable> [ ( <replaceable class="parameter">column_name</replaceable> [, ...] ) ] AS ( <replaceable class="parameter">select</replaceable> )
|
||||||
|
|
||||||
|
TABLE <replaceable class="parameter">table_name</replaceable> | <replaceable class="parameter">with_query_name</replaceable>
|
||||||
</synopsis>
|
</synopsis>
|
||||||
|
|
||||||
</refsynopsisdiv>
|
</refsynopsisdiv>
|
||||||
@ -1071,6 +1078,23 @@ ROLLBACK TO s;
|
|||||||
</para>
|
</para>
|
||||||
</caution>
|
</caution>
|
||||||
</refsect2>
|
</refsect2>
|
||||||
|
|
||||||
|
<refsect2 id="SQL-TABLE">
|
||||||
|
<title><literal>TABLE</literal> Command</title>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The command
|
||||||
|
<programlisting>
|
||||||
|
TABLE <replaceable class="parameter">name</replaceable>
|
||||||
|
</programlisting>
|
||||||
|
is completely equivalent to
|
||||||
|
<programlisting>
|
||||||
|
SELECT * FROM <replaceable class="parameter">name</replaceable>
|
||||||
|
</programlisting>
|
||||||
|
It can be used as a top-level command or as a space-saving syntax
|
||||||
|
variant in parts of complex queries.
|
||||||
|
</para>
|
||||||
|
</refsect2>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
|
@ -280,7 +280,7 @@ F591 Derived tables YES
|
|||||||
F611 Indicator data types YES
|
F611 Indicator data types YES
|
||||||
F641 Row and table constructors NO
|
F641 Row and table constructors NO
|
||||||
F651 Catalog name qualifiers YES
|
F651 Catalog name qualifiers YES
|
||||||
F661 Simple tables NO
|
F661 Simple tables YES
|
||||||
F671 Subqueries in CHECK NO intentionally omitted
|
F671 Subqueries in CHECK NO intentionally omitted
|
||||||
F672 Retrospective check constraints YES
|
F672 Retrospective check constraints YES
|
||||||
F690 Collation support NO
|
F690 Collation support NO
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.637 2008/11/13 11:10:06 meskes Exp $
|
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.638 2008/11/20 14:04:46 petere Exp $
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
@ -6431,6 +6431,28 @@ simple_select:
|
|||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
| values_clause { $$ = $1; }
|
| values_clause { $$ = $1; }
|
||||||
|
| TABLE qualified_name
|
||||||
|
{
|
||||||
|
/* same as SELECT * FROM qualified_name */
|
||||||
|
ColumnRef *cr = makeNode(ColumnRef);
|
||||||
|
ResTarget *rt = makeNode(ResTarget);
|
||||||
|
SelectStmt *n = makeNode(SelectStmt);
|
||||||
|
|
||||||
|
cr->fields = list_make1(makeNode(A_Star));
|
||||||
|
cr->location = -1;
|
||||||
|
|
||||||
|
rt->name = NULL;
|
||||||
|
rt->indirection = NIL;
|
||||||
|
rt->val = (Node *)cr;
|
||||||
|
rt->location = -1;
|
||||||
|
|
||||||
|
$2->inhOpt = INH_DEFAULT;
|
||||||
|
$2->alias = NULL;
|
||||||
|
|
||||||
|
n->targetList = list_make1(rt);
|
||||||
|
n->fromClause = list_make1($2);
|
||||||
|
$$ = (Node *)n;
|
||||||
|
}
|
||||||
| select_clause UNION opt_all select_clause
|
| select_clause UNION opt_all select_clause
|
||||||
{
|
{
|
||||||
$$ = makeSetOp(SETOP_UNION, $3, $1, $4);
|
$$ = makeSetOp(SETOP_UNION, $3, $1, $4);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.176 2008/11/11 02:42:32 tgl Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.177 2008/11/20 14:04:46 petere Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*----------------------------------------------------------------------
|
/*----------------------------------------------------------------------
|
||||||
@ -615,7 +615,7 @@ psql_completion(char *text, int start, int end)
|
|||||||
"DELETE FROM", "DISCARD", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH",
|
"DELETE FROM", "DISCARD", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH",
|
||||||
"GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE",
|
"GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE",
|
||||||
"REASSIGN", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK",
|
"REASSIGN", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK",
|
||||||
"SAVEPOINT", "SELECT", "SET", "SHOW", "START", "TRUNCATE", "UNLISTEN",
|
"SAVEPOINT", "SELECT", "SET", "SHOW", "START", "TABLE", "TRUNCATE", "UNLISTEN",
|
||||||
"UPDATE", "VACUUM", "VALUES", "WITH", NULL
|
"UPDATE", "VACUUM", "VALUES", "WITH", NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1694,24 +1694,24 @@ psql_completion(char *text, int start, int end)
|
|||||||
COMPLETE_WITH_ATTR(prev_wd, "");
|
COMPLETE_WITH_ATTR(prev_wd, "");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Complete INSERT INTO <table> with "VALUES" or "SELECT" or "DEFAULT
|
* Complete INSERT INTO <table> with "VALUES" or "SELECT" or
|
||||||
* VALUES"
|
* "TABLE" or "DEFAULT VALUES"
|
||||||
*/
|
*/
|
||||||
else if (pg_strcasecmp(prev3_wd, "INSERT") == 0 &&
|
else if (pg_strcasecmp(prev3_wd, "INSERT") == 0 &&
|
||||||
pg_strcasecmp(prev2_wd, "INTO") == 0)
|
pg_strcasecmp(prev2_wd, "INTO") == 0)
|
||||||
{
|
{
|
||||||
static const char *const list_INSERT[] =
|
static const char *const list_INSERT[] =
|
||||||
{"DEFAULT VALUES", "SELECT", "VALUES", NULL};
|
{"DEFAULT VALUES", "SELECT", "TABLE", "VALUES", NULL};
|
||||||
|
|
||||||
COMPLETE_WITH_LIST(list_INSERT);
|
COMPLETE_WITH_LIST(list_INSERT);
|
||||||
}
|
}
|
||||||
/* Complete INSERT INTO <table> (attribs) with "VALUES" or "SELECT" */
|
/* Complete INSERT INTO <table> (attribs) with "VALUES" or "SELECT" or "TABLE" */
|
||||||
else if (pg_strcasecmp(prev4_wd, "INSERT") == 0 &&
|
else if (pg_strcasecmp(prev4_wd, "INSERT") == 0 &&
|
||||||
pg_strcasecmp(prev3_wd, "INTO") == 0 &&
|
pg_strcasecmp(prev3_wd, "INTO") == 0 &&
|
||||||
prev_wd[strlen(prev_wd) - 1] == ')')
|
prev_wd[strlen(prev_wd) - 1] == ')')
|
||||||
{
|
{
|
||||||
static const char *const list_INSERT[] =
|
static const char *const list_INSERT[] =
|
||||||
{"SELECT", "VALUES", NULL};
|
{"SELECT", "TABLE", "VALUES", NULL};
|
||||||
|
|
||||||
COMPLETE_WITH_LIST(list_INSERT);
|
COMPLETE_WITH_LIST(list_INSERT);
|
||||||
}
|
}
|
||||||
|
@ -506,7 +506,7 @@ VALUES (1,2), (3,4+4), (7,77.7)
|
|||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT 2+2, 57
|
SELECT 2+2, 57
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT * FROM int8_tbl;
|
TABLE int8_tbl;
|
||||||
column1 | column2
|
column1 | column2
|
||||||
------------------+-------------------
|
------------------+-------------------
|
||||||
1 | 2
|
1 | 2
|
||||||
|
@ -146,7 +146,7 @@ VALUES (1,2), (3,4+4), (7,77.7)
|
|||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT 2+2, 57
|
SELECT 2+2, 57
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT * FROM int8_tbl;
|
TABLE int8_tbl;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Test ORDER BY options
|
-- Test ORDER BY options
|
||||||
|
Loading…
x
Reference in New Issue
Block a user