diff options
author | Fujii Masao <fujii@postgresql.org> | 2019-09-13 18:16:40 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2019-09-13 18:16:40 +0900 |
commit | fc16778873d081b07930d642622ee0cf22c3f9b7 (patch) | |
tree | 57464324a139e2069740bff96110c1a8720a51f2 | |
parent | 3b6b54f178d7539354064727cca9b4ff2eca0fce (diff) | |
download | postgresql-fc16778873d081b07930d642622ee0cf22c3f9b7.tar.gz postgresql-fc16778873d081b07930d642622ee0cf22c3f9b7.zip |
Add tab completion for CREATE OR REPLACE in psql.
Author: Shenhao Wang
Discussion: https://postgr.es/m/63580B24E208E3429D94153A03C68E0901AA8002D5@G08CNEXMBPEKD02.g08.fujitsu.local
-rw-r--r-- | src/bin/psql/tab-complete.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 890fc5322d0..cb126682764 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 <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 */ |