From b09a1a2942628477973f25d564f7698baf54df1c Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 20 Nov 2008 14:04:46 +0000 Subject: [PATCH] TABLE command --- doc/src/sgml/ref/create_table_as.sgml | 18 +++++++++++++++--- doc/src/sgml/ref/select.sgml | 26 +++++++++++++++++++++++++- src/backend/catalog/sql_features.txt | 2 +- src/backend/parser/gram.y | 24 +++++++++++++++++++++++- src/bin/psql/tab-complete.c | 14 +++++++------- src/test/regress/expected/select.out | 2 +- src/test/regress/sql/select.sql | 2 +- 7 files changed, 73 insertions(+), 15 deletions(-) diff --git a/doc/src/sgml/ref/create_table_as.sgml b/doc/src/sgml/ref/create_table_as.sgml index bf3c78896b..b31a25704f 100644 --- a/doc/src/sgml/ref/create_table_as.sgml +++ b/doc/src/sgml/ref/create_table_as.sgml @@ -1,5 +1,5 @@ @@ -196,10 +196,12 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name query - A or + A , TABLE, + or command, or an command - that runs a prepared SELECT or VALUES query. + that runs a prepared SELECT, TABLE, or VALUES query. @@ -260,6 +262,16 @@ CREATE TABLE films_recent AS + + To copy a table completely, the short form using + the TABLE command can also be used: + + +CREATE TABLE films2 AS + TABLE films; + + + Create a new temporary table films_recent, consisting of only recent entries from the table films, using a diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml index 75ef1ee1f2..68ec391238 100644 --- a/doc/src/sgml/ref/select.sgml +++ b/doc/src/sgml/ref/select.sgml @@ -1,5 +1,5 @@ @@ -12,6 +12,7 @@ PostgreSQL documentation SELECT + TABLE WITH retrieve rows from a table or view @@ -20,6 +21,10 @@ PostgreSQL documentation SELECT + + TABLE command + + WITH in SELECT @@ -53,6 +58,8 @@ where from_item can be one of: and with_query is: with_query_name [ ( column_name [, ...] ) ] AS ( select ) + +TABLE table_name | with_query_name @@ -1071,6 +1078,23 @@ ROLLBACK TO s; + + + <literal>TABLE</literal> Command + + + The command + +TABLE name + + is completely equivalent to + +SELECT * FROM name + + It can be used as a top-level command or as a space-saving syntax + variant in parts of complex queries. + + diff --git a/src/backend/catalog/sql_features.txt b/src/backend/catalog/sql_features.txt index 354fd98811..3afffa814a 100644 --- a/src/backend/catalog/sql_features.txt +++ b/src/backend/catalog/sql_features.txt @@ -280,7 +280,7 @@ F591 Derived tables YES F611 Indicator data types YES F641 Row and table constructors NO F651 Catalog name qualifiers YES -F661 Simple tables NO +F661 Simple tables YES F671 Subqueries in CHECK NO intentionally omitted F672 Retrospective check constraints YES F690 Collation support NO diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b3046c04b2..6733372da2 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11,7 +11,7 @@ * * * 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 * AUTHOR DATE MAJOR EVENT @@ -6431,6 +6431,28 @@ simple_select: $$ = (Node *)n; } | 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 { $$ = makeSetOp(SETOP_UNION, $3, $1, $4); diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index d262f21771..635e0c7fa7 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3,7 +3,7 @@ * * 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", "GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE", "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 }; @@ -1694,24 +1694,24 @@ psql_completion(char *text, int start, int end) COMPLETE_WITH_ATTR(prev_wd, ""); /* - * Complete INSERT INTO with "VALUES" or "SELECT" or "DEFAULT - * VALUES" + * Complete INSERT INTO
with "VALUES" or "SELECT" or + * "TABLE" or "DEFAULT VALUES" */ else if (pg_strcasecmp(prev3_wd, "INSERT") == 0 && pg_strcasecmp(prev2_wd, "INTO") == 0) { static const char *const list_INSERT[] = - {"DEFAULT VALUES", "SELECT", "VALUES", NULL}; + {"DEFAULT VALUES", "SELECT", "TABLE", "VALUES", NULL}; COMPLETE_WITH_LIST(list_INSERT); } - /* Complete INSERT INTO
(attribs) with "VALUES" or "SELECT" */ + /* Complete INSERT INTO
(attribs) with "VALUES" or "SELECT" or "TABLE" */ else if (pg_strcasecmp(prev4_wd, "INSERT") == 0 && pg_strcasecmp(prev3_wd, "INTO") == 0 && prev_wd[strlen(prev_wd) - 1] == ')') { static const char *const list_INSERT[] = - {"SELECT", "VALUES", NULL}; + {"SELECT", "TABLE", "VALUES", NULL}; COMPLETE_WITH_LIST(list_INSERT); } diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out index 2936f0306a..19a0b9caae 100644 --- a/src/test/regress/expected/select.out +++ b/src/test/regress/expected/select.out @@ -506,7 +506,7 @@ VALUES (1,2), (3,4+4), (7,77.7) UNION ALL SELECT 2+2, 57 UNION ALL -SELECT * FROM int8_tbl; +TABLE int8_tbl; column1 | column2 ------------------+------------------- 1 | 2 diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql index bb1fc9b934..a9ddd5e586 100644 --- a/src/test/regress/sql/select.sql +++ b/src/test/regress/sql/select.sql @@ -146,7 +146,7 @@ VALUES (1,2), (3,4+4), (7,77.7) UNION ALL SELECT 2+2, 57 UNION ALL -SELECT * FROM int8_tbl; +TABLE int8_tbl; -- -- Test ORDER BY options -- 2.40.0