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/e462b251-99a7-4abc-aedc-214688742c80@darold.net
This commit is contained in:
Michael Paquier 2023-11-16 09:44:29 +09:00
parent 69c32b8b35
commit 816f10564a
1 changed files with 10 additions and 4 deletions

View File

@ -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") ||