Skip to content

Commit b09a1a2

Browse files
committed
TABLE command
1 parent f179d5e commit b09a1a2

File tree

7 files changed

+73
-15
lines changed

7 files changed

+73
-15
lines changed

doc/src/sgml/ref/create_table_as.sgml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.39 2008/11/14 10:22:46 petere Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.40 2008/11/20 14:04:45 petere Exp $
33
PostgreSQL documentation
44
-->
55

@@ -196,10 +196,12 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
196196
<term><replaceable>query</replaceable></term>
197197
<listitem>
198198
<para>
199-
A <xref linkend="sql-select" endterm="sql-select-title"> or
199+
A <xref linkend="sql-select"
200+
endterm="sql-select-title">, <link linkend="sql-table">TABLE</link>,
201+
or
200202
<xref linkend="sql-values" endterm="sql-values-title"> command,
201203
or an <xref linkend="sql-execute" endterm="sql-execute-title"> command
202-
that runs a prepared <command>SELECT</> or <command>VALUES</> query.
204+
that runs a prepared <command>SELECT</>, <command>TABLE</>, or <command>VALUES</> query.
203205
</para>
204206
</listitem>
205207
</varlistentry>
@@ -260,6 +262,16 @@ CREATE TABLE films_recent AS
260262
</programlisting>
261263
</para>
262264

265+
<para>
266+
To copy a table completely, the short form using
267+
the <literal>TABLE</literal> command can also be used:
268+
269+
<programlisting>
270+
CREATE TABLE films2 AS
271+
TABLE films;
272+
</programlisting>
273+
</para>
274+
263275
<para>
264276
Create a new temporary table <literal>films_recent</literal>, consisting of
265277
only recent entries from the table <literal>films</literal>, using a

doc/src/sgml/ref/select.sgml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.109 2008/11/19 12:21:57 petere Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.110 2008/11/20 14:04:45 petere Exp $
33
PostgreSQL documentation
44
-->
55

@@ -12,6 +12,7 @@ PostgreSQL documentation
1212

1313
<refnamediv>
1414
<refname>SELECT</refname>
15+
<refname>TABLE</refname>
1516
<refname>WITH</refname>
1617
<refpurpose>retrieve rows from a table or view</refpurpose>
1718
</refnamediv>
@@ -20,6 +21,10 @@ PostgreSQL documentation
2021
<primary>SELECT</primary>
2122
</indexterm>
2223

24+
<indexterm zone="sql-select">
25+
<primary>TABLE command</primary>
26+
</indexterm>
27+
2328
<indexterm zone="sql-select">
2429
<primary>WITH</primary>
2530
<secondary>in SELECT</secondary>
@@ -53,6 +58,8 @@ where <replaceable class="parameter">from_item</replaceable> can be one of:
5358
and <replaceable class="parameter">with_query</replaceable> is:
5459

5560
<replaceable class="parameter">with_query_name</replaceable> [ ( <replaceable class="parameter">column_name</replaceable> [, ...] ) ] AS ( <replaceable class="parameter">select</replaceable> )
61+
62+
TABLE <replaceable class="parameter">table_name</replaceable> | <replaceable class="parameter">with_query_name</replaceable>
5663
</synopsis>
5764

5865
</refsynopsisdiv>
@@ -1071,6 +1078,23 @@ ROLLBACK TO s;
10711078
</para>
10721079
</caution>
10731080
</refsect2>
1081+
1082+
<refsect2 id="SQL-TABLE">
1083+
<title><literal>TABLE</literal> Command</title>
1084+
1085+
<para>
1086+
The command
1087+
<programlisting>
1088+
TABLE <replaceable class="parameter">name</replaceable>
1089+
</programlisting>
1090+
is completely equivalent to
1091+
<programlisting>
1092+
SELECT * FROM <replaceable class="parameter">name</replaceable>
1093+
</programlisting>
1094+
It can be used as a top-level command or as a space-saving syntax
1095+
variant in parts of complex queries.
1096+
</para>
1097+
</refsect2>
10741098
</refsect1>
10751099

10761100
<refsect1>

src/backend/catalog/sql_features.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ F591 Derived tables YES
280280
F611 Indicator data types YES
281281
F641 Row and table constructors NO
282282
F651 Catalog name qualifiers YES
283-
F661 Simple tables NO
283+
F661 Simple tables YES
284284
F671 Subqueries in CHECK NO intentionally omitted
285285
F672 Retrospective check constraints YES
286286
F690 Collation support NO

src/backend/parser/gram.y

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.637 2008/11/13 11:10:06 meskes Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.638 2008/11/20 14:04:46 petere Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -6431,6 +6431,28 @@ simple_select:
64316431
$$ = (Node *)n;
64326432
}
64336433
| values_clause { $$ = $1; }
6434+
| TABLE qualified_name
6435+
{
6436+
/* same as SELECT * FROM qualified_name */
6437+
ColumnRef *cr = makeNode(ColumnRef);
6438+
ResTarget *rt = makeNode(ResTarget);
6439+
SelectStmt *n = makeNode(SelectStmt);
6440+
6441+
cr->fields = list_make1(makeNode(A_Star));
6442+
cr->location = -1;
6443+
6444+
rt->name = NULL;
6445+
rt->indirection = NIL;
6446+
rt->val = (Node *)cr;
6447+
rt->location = -1;
6448+
6449+
$2->inhOpt = INH_DEFAULT;
6450+
$2->alias = NULL;
6451+
6452+
n->targetList = list_make1(rt);
6453+
n->fromClause = list_make1($2);
6454+
$$ = (Node *)n;
6455+
}
64346456
| select_clause UNION opt_all select_clause
64356457
{
64366458
$$ = makeSetOp(SETOP_UNION, $3, $1, $4);

src/bin/psql/tab-complete.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.176 2008/11/11 02:42:32 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.177 2008/11/20 14:04:46 petere Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -615,7 +615,7 @@ psql_completion(char *text, int start, int end)
615615
"DELETE FROM", "DISCARD", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH",
616616
"GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE",
617617
"REASSIGN", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK",
618-
"SAVEPOINT", "SELECT", "SET", "SHOW", "START", "TRUNCATE", "UNLISTEN",
618+
"SAVEPOINT", "SELECT", "SET", "SHOW", "START", "TABLE", "TRUNCATE", "UNLISTEN",
619619
"UPDATE", "VACUUM", "VALUES", "WITH", NULL
620620
};
621621

@@ -1694,24 +1694,24 @@ psql_completion(char *text, int start, int end)
16941694
COMPLETE_WITH_ATTR(prev_wd, "");
16951695

16961696
/*
1697-
* Complete INSERT INTO <table> with "VALUES" or "SELECT" or "DEFAULT
1698-
* VALUES"
1697+
* Complete INSERT INTO <table> with "VALUES" or "SELECT" or
1698+
* "TABLE" or "DEFAULT VALUES"
16991699
*/
17001700
else if (pg_strcasecmp(prev3_wd, "INSERT") == 0 &&
17011701
pg_strcasecmp(prev2_wd, "INTO") == 0)
17021702
{
17031703
static const char *const list_INSERT[] =
1704-
{"DEFAULT VALUES", "SELECT", "VALUES", NULL};
1704+
{"DEFAULT VALUES", "SELECT", "TABLE", "VALUES", NULL};
17051705

17061706
COMPLETE_WITH_LIST(list_INSERT);
17071707
}
1708-
/* Complete INSERT INTO <table> (attribs) with "VALUES" or "SELECT" */
1708+
/* Complete INSERT INTO <table> (attribs) with "VALUES" or "SELECT" or "TABLE" */
17091709
else if (pg_strcasecmp(prev4_wd, "INSERT") == 0 &&
17101710
pg_strcasecmp(prev3_wd, "INTO") == 0 &&
17111711
prev_wd[strlen(prev_wd) - 1] == ')')
17121712
{
17131713
static const char *const list_INSERT[] =
1714-
{"SELECT", "VALUES", NULL};
1714+
{"SELECT", "TABLE", "VALUES", NULL};
17151715

17161716
COMPLETE_WITH_LIST(list_INSERT);
17171717
}

src/test/regress/expected/select.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ VALUES (1,2), (3,4+4), (7,77.7)
506506
UNION ALL
507507
SELECT 2+2, 57
508508
UNION ALL
509-
SELECT * FROM int8_tbl;
509+
TABLE int8_tbl;
510510
column1 | column2
511511
------------------+-------------------
512512
1 | 2

src/test/regress/sql/select.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ VALUES (1,2), (3,4+4), (7,77.7)
146146
UNION ALL
147147
SELECT 2+2, 57
148148
UNION ALL
149-
SELECT * FROM int8_tbl;
149+
TABLE int8_tbl;
150150

151151
--
152152
-- Test ORDER BY options

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy