diff options
author | Michael Paquier | 2023-11-16 00:44:29 +0000 |
---|---|---|
committer | Michael Paquier | 2023-11-16 00:44:29 +0000 |
commit | 816f10564a8671918e170a547625584d10587cf4 (patch) | |
tree | 6e3f459fbe79fa2a4b5fdae61ec993b847ba7910 | |
parent | 69c32b8b3535f7f367cca90a09d9557d575b270c (diff) |
psql: Add some completion support for CREATE TABLE .. AS
"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/[email protected]
-rw-r--r-- | src/bin/psql/tab-complete.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 93742fc6ac..006e10f5d2 100644 --- 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") || |