From 816f10564a8671918e170a547625584d10587cf4 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Thu, 16 Nov 2023 09:44:29 +0900 Subject: [PATCH] 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] [ (...) ] AS Author: Gilles Darold Reviewed-by: Jim Jones Discussion: https://postgr.es/m/e462b251-99a7-4abc-aedc-214688742c80@darold.net --- src/bin/psql/tab-complete.c | 14 ++++++++++---- 1 file 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 with '(', OF or PARTITION OF */ + /* Complete CREATE TABLE 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 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 [ (...) ] 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") || -- 2.30.2