Skip to content

Commit 816f105

Browse files
committed
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
1 parent 69c32b8 commit 816f105

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/bin/psql/tab-complete.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,20 +3228,26 @@ psql_completion(const char *text, int start, int end)
32283228
/* Limited completion support for partition bound specification */
32293229
else if (TailMatches("PARTITION", "OF", MatchAny))
32303230
COMPLETE_WITH("FOR VALUES", "DEFAULT");
3231-
/* Complete CREATE TABLE <name> with '(', OF or PARTITION OF */
3231+
/* Complete CREATE TABLE <name> with '(', AS, OF or PARTITION OF */
32323232
else if (TailMatches("CREATE", "TABLE", MatchAny) ||
32333233
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny))
3234-
COMPLETE_WITH("(", "OF", "PARTITION OF");
3234+
COMPLETE_WITH("(", "AS", "OF", "PARTITION OF");
32353235
/* Complete CREATE TABLE <name> OF with list of composite types */
32363236
else if (TailMatches("CREATE", "TABLE", MatchAny, "OF") ||
32373237
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "OF"))
32383238
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes);
3239+
/* Complete CREATE TABLE <name> [ (...) ] AS with list of keywords */
3240+
else if (TailMatches("CREATE", "TABLE", MatchAny, "AS") ||
3241+
TailMatches("CREATE", "TABLE", MatchAny, "(*)", "AS") ||
3242+
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "AS") ||
3243+
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(*)", "AS"))
3244+
COMPLETE_WITH("EXECUTE", "SELECT", "TABLE", "VALUES", "WITH");
32393245
/* Complete CREATE TABLE name (...) with supported options */
32403246
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)") ||
32413247
TailMatches("CREATE", "UNLOGGED", "TABLE", MatchAny, "(*)"))
3242-
COMPLETE_WITH("INHERITS (", "PARTITION BY", "USING", "TABLESPACE", "WITH (");
3248+
COMPLETE_WITH("AS", "INHERITS (", "PARTITION BY", "USING", "TABLESPACE", "WITH (");
32433249
else if (TailMatches("CREATE", "TEMP|TEMPORARY", "TABLE", MatchAny, "(*)"))
3244-
COMPLETE_WITH("INHERITS (", "ON COMMIT", "PARTITION BY",
3250+
COMPLETE_WITH("AS", "INHERITS (", "ON COMMIT", "PARTITION BY",
32453251
"TABLESPACE", "WITH (");
32463252
/* Complete CREATE TABLE (...) USING with table access methods */
32473253
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "USING") ||

0 commit comments

Comments
 (0)