]> granicus.if.org Git - postgresql/commitdiff
Add tab completion for CREATE OR REPLACE in psql.
authorFujii Masao <fujii@postgresql.org>
Fri, 13 Sep 2019 09:16:40 +0000 (18:16 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 13 Sep 2019 09:16:40 +0000 (18:16 +0900)
Author: Shenhao Wang
Discussion: https://postgr.es/m/63580B24E208E3429D94153A03C68E0901AA8002D5@G08CNEXMBPEKD02.g08.fujitsu.local

src/bin/psql/tab-complete.c

index 890fc5322d0b8873a7e24d34f555c1fe6183d25e..cb1266827645a7f155d6e48924556dbc3569d88d 100644 (file)
@@ -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 <name> 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 <sth>" with "AS ON" */
-       else if (Matches("CREATE", "RULE", MatchAny))
+       /* Complete "CREATE [ OR REPLACE ] RULE <sth>" with "AS ON" */
+       else if (Matches("CREATE", "RULE", MatchAny) ||
+                        Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny))
                COMPLETE_WITH("AS ON");
-       /* Complete "CREATE RULE <sth> AS" with "ON" */
-       else if (Matches("CREATE", "RULE", MatchAny, "AS"))
+       /* Complete "CREATE [ OR REPLACE ] RULE <sth> AS" with "ON" */
+       else if (Matches("CREATE", "RULE", MatchAny, "AS") ||
+                        Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS"))
                COMPLETE_WITH("ON");
-       /* Complete "CREATE RULE <sth> AS ON" with SELECT|UPDATE|INSERT|DELETE */
-       else if (Matches("CREATE", "RULE", MatchAny, "AS", "ON"))
+       /* Complete "CREATE [ OR REPLACE ] RULE <sth> 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 <name> with AS */
-       else if (TailMatches("CREATE", "VIEW", MatchAny))
+       /* Complete CREATE [ OR REPLACE ] VIEW <name> with AS */
+       else if (TailMatches("CREATE", "VIEW", MatchAny) ||
+                        TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny))
                COMPLETE_WITH("AS");
-       /* Complete "CREATE VIEW <sth> AS with "SELECT" */
-       else if (TailMatches("CREATE", "VIEW", MatchAny, "AS"))
+       /* Complete "CREATE [ OR REPLACE ] VIEW <sth> AS with "SELECT" */
+       else if (TailMatches("CREATE", "VIEW", MatchAny, "AS") ||
+                        TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "AS"))
                COMPLETE_WITH("SELECT");
 
 /* CREATE MATERIALIZED VIEW */