From: Fujii Masao Date: Fri, 13 Sep 2019 09:16:40 +0000 (+0900) Subject: Add tab completion for CREATE OR REPLACE in psql. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc16778873d081b07930d642622ee0cf22c3f9b7;p=postgresql Add tab completion for CREATE OR REPLACE in psql. Author: Shenhao Wang Discussion: https://postgr.es/m/63580B24E208E3429D94153A03C68E0901AA8002D5@G08CNEXMBPEKD02.g08.fujitsu.local --- diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 890fc5322d..cb12668276 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1007,6 +1007,7 @@ static const pgsql_thing_t words_after_create[] = { {"MATERIALIZED VIEW", NULL, NULL, &Query_for_list_of_matviews}, {"OPERATOR", NULL, NULL, NULL}, /* Querying for this is probably not such * a good idea. */ + {"OR REPLACE", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, {"OWNED", NULL, NULL, NULL, THING_NO_CREATE | THING_NO_ALTER}, /* for DROP OWNED BY ... */ {"PARSER", Query_for_list_of_ts_parsers, NULL, NULL, THING_NO_SHOW}, {"POLICY", NULL, NULL, NULL}, @@ -1489,6 +1490,11 @@ psql_completion(const char *text, int start, int end) else if (TailMatches("CREATE")) matches = completion_matches(text, create_command_generator); + /* complete with somthing you can create or replace */ + else if (TailMatches("CREATE", "OR", "REPLACE")) + COMPLETE_WITH("FUNCTION", "PROCEDURE", "LANGUAGE", "RULE", "VIEW", + "AGGREGATE", "TRANSFORM"); + /* DROP, but not DROP embedded in other commands */ /* complete with something you can drop */ else if (Matches("DROP")) @@ -2345,6 +2351,10 @@ psql_completion(const char *text, int start, int end) !TailMatches("FOR", MatchAny, MatchAny, MatchAny)) COMPLETE_WITH("("); + /* CREATE OR REPLACE */ + else if (Matches("CREATE", "OR")) + COMPLETE_WITH("REPLACE"); + /* CREATE POLICY */ /* Complete "CREATE POLICY ON" */ else if (Matches("CREATE", "POLICY", MatchAny)) @@ -2440,14 +2450,17 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH("publish"); /* CREATE RULE */ - /* Complete "CREATE RULE " with "AS ON" */ - else if (Matches("CREATE", "RULE", MatchAny)) + /* Complete "CREATE [ OR REPLACE ] RULE " with "AS ON" */ + else if (Matches("CREATE", "RULE", MatchAny) || + Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny)) COMPLETE_WITH("AS ON"); - /* Complete "CREATE RULE AS" with "ON" */ - else if (Matches("CREATE", "RULE", MatchAny, "AS")) + /* Complete "CREATE [ OR REPLACE ] RULE AS" with "ON" */ + else if (Matches("CREATE", "RULE", MatchAny, "AS") || + Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS")) COMPLETE_WITH("ON"); - /* Complete "CREATE RULE AS ON" with SELECT|UPDATE|INSERT|DELETE */ - else if (Matches("CREATE", "RULE", MatchAny, "AS", "ON")) + /* Complete "CREATE [ OR REPLACE ] RULE AS ON" with SELECT|UPDATE|INSERT|DELETE */ + else if (Matches("CREATE", "RULE", MatchAny, "AS", "ON") || + Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS", "ON")) COMPLETE_WITH("SELECT", "UPDATE", "INSERT", "DELETE"); /* Complete "AS ON SELECT|UPDATE|INSERT|DELETE" with a "TO" */ else if (TailMatches("AS", "ON", "SELECT|UPDATE|INSERT|DELETE")) @@ -2726,11 +2739,13 @@ psql_completion(const char *text, int start, int end) } /* CREATE VIEW --- is allowed inside CREATE SCHEMA, so use TailMatches */ - /* Complete CREATE VIEW with AS */ - else if (TailMatches("CREATE", "VIEW", MatchAny)) + /* Complete CREATE [ OR REPLACE ] VIEW with AS */ + else if (TailMatches("CREATE", "VIEW", MatchAny) || + TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny)) COMPLETE_WITH("AS"); - /* Complete "CREATE VIEW AS with "SELECT" */ - else if (TailMatches("CREATE", "VIEW", MatchAny, "AS")) + /* Complete "CREATE [ OR REPLACE ] VIEW AS with "SELECT" */ + else if (TailMatches("CREATE", "VIEW", MatchAny, "AS") || + TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "AS")) COMPLETE_WITH("SELECT"); /* CREATE MATERIALIZED VIEW */