git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 69c32b8)
psql: Add some completion support for CREATE TABLE .. AS
2023年11月16日 00:44:29 +0000 (09:44 +0900)
2023年11月16日 00:44:29 +0000 (09:44 +0900)
"AS" is added as a suggested keyword for CREATE TABLE for a few query
patterns, including the case where a list of columns is given in
parenthesis.

More queries can be now completed with the keywords supported for
queries in a CTAS, after:
CREATE TABLE [TEMP|TEMPORARY|UNLOGGED] <name> [ (...) ] AS

Author: Gilles Darold
Reviewed-by: Jim Jones
Discussion: https://postgr.es/m/e462b251-99a7-4abc-aedc-214688742c80@darold.net


diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 93742fc6ac9fc627d6174fbffcb841c6589bd3ec..006e10f5d2d9b3fa1e6fd1d4279fa2506f7efa33 100644 (file)
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3228,20 +3228,26 @@ psql_completion(const char *text, int start, int end)
/* Limited completion support for partition bound specification */
else if (TailMatches("PARTITION", "OF", MatchAny))
COMPLETE_WITH("FOR VALUES", "DEFAULT");
- /* Complete CREATE TABLE <name> with '(', OF or PARTITION OF */
+ /* Complete CREATE TABLE <name> with '(', AS, OF or PARTITION OF */
else if (TailMatches("CREATE", "TABLE", MatchAny) ||
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny))
- COMPLETE_WITH("(", "OF", "PARTITION OF");
+ COMPLETE_WITH("(", "AS", "OF", "PARTITION OF");
/* Complete CREATE TABLE <name> OF with list of composite types */
else if (TailMatches("CREATE", "TABLE", MatchAny, "OF") ||
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "OF"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes);
+ /* Complete CREATE TABLE <name> [ (...) ] AS with list of keywords */
+ else if (TailMatches("CREATE", "TABLE", MatchAny, "AS") ||
+ TailMatches("CREATE", "TABLE", MatchAny, "(*)", "AS") ||
+ TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "AS") ||
+ TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(*)", "AS"))
+ COMPLETE_WITH("EXECUTE", "SELECT", "TABLE", "VALUES", "WITH");
/* Complete CREATE TABLE name (...) with supported options */
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)") ||
TailMatches("CREATE", "UNLOGGED", "TABLE", MatchAny, "(*)"))
- COMPLETE_WITH("INHERITS (", "PARTITION BY", "USING", "TABLESPACE", "WITH (");
+ COMPLETE_WITH("AS", "INHERITS (", "PARTITION BY", "USING", "TABLESPACE", "WITH (");
else if (TailMatches("CREATE", "TEMP|TEMPORARY", "TABLE", MatchAny, "(*)"))
- COMPLETE_WITH("INHERITS (", "ON COMMIT", "PARTITION BY",
+ COMPLETE_WITH("AS", "INHERITS (", "ON COMMIT", "PARTITION BY",
"TABLESPACE", "WITH (");
/* Complete CREATE TABLE (...) USING with table access methods */
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "USING") ||
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /