Skip to content

Commit fc16778

Browse files
committed
Add tab completion for CREATE OR REPLACE in psql.
Author: Shenhao Wang Discussion: https://postgr.es/m/63580B24E208E3429D94153A03C68E0901AA8002D5@G08CNEXMBPEKD02.g08.fujitsu.local
1 parent 3b6b54f commit fc16778

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/bin/psql/tab-complete.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ static const pgsql_thing_t words_after_create[] = {
10071007
{"MATERIALIZED VIEW", NULL, NULL, &Query_for_list_of_matviews},
10081008
{"OPERATOR", NULL, NULL, NULL}, /* Querying for this is probably not such
10091009
* a good idea. */
1010+
{"OR REPLACE", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER},
10101011
{"OWNED", NULL, NULL, NULL, THING_NO_CREATE | THING_NO_ALTER}, /* for DROP OWNED BY ... */
10111012
{"PARSER", Query_for_list_of_ts_parsers, NULL, NULL, THING_NO_SHOW},
10121013
{"POLICY", NULL, NULL, NULL},
@@ -1489,6 +1490,11 @@ psql_completion(const char *text, int start, int end)
14891490
else if (TailMatches("CREATE"))
14901491
matches = completion_matches(text, create_command_generator);
14911492

1493+
/* complete with somthing you can create or replace */
1494+
else if (TailMatches("CREATE", "OR", "REPLACE"))
1495+
COMPLETE_WITH("FUNCTION", "PROCEDURE", "LANGUAGE", "RULE", "VIEW",
1496+
"AGGREGATE", "TRANSFORM");
1497+
14921498
/* DROP, but not DROP embedded in other commands */
14931499
/* complete with something you can drop */
14941500
else if (Matches("DROP"))
@@ -2345,6 +2351,10 @@ psql_completion(const char *text, int start, int end)
23452351
!TailMatches("FOR", MatchAny, MatchAny, MatchAny))
23462352
COMPLETE_WITH("(");
23472353

2354+
/* CREATE OR REPLACE */
2355+
else if (Matches("CREATE", "OR"))
2356+
COMPLETE_WITH("REPLACE");
2357+
23482358
/* CREATE POLICY */
23492359
/* Complete "CREATE POLICY <name> ON" */
23502360
else if (Matches("CREATE", "POLICY", MatchAny))
@@ -2440,14 +2450,17 @@ psql_completion(const char *text, int start, int end)
24402450
COMPLETE_WITH("publish");
24412451

24422452
/* CREATE RULE */
2443-
/* Complete "CREATE RULE <sth>" with "AS ON" */
2444-
else if (Matches("CREATE", "RULE", MatchAny))
2453+
/* Complete "CREATE [ OR REPLACE ] RULE <sth>" with "AS ON" */
2454+
else if (Matches("CREATE", "RULE", MatchAny) ||
2455+
Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny))
24452456
COMPLETE_WITH("AS ON");
2446-
/* Complete "CREATE RULE <sth> AS" with "ON" */
2447-
else if (Matches("CREATE", "RULE", MatchAny, "AS"))
2457+
/* Complete "CREATE [ OR REPLACE ] RULE <sth> AS" with "ON" */
2458+
else if (Matches("CREATE", "RULE", MatchAny, "AS") ||
2459+
Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS"))
24482460
COMPLETE_WITH("ON");
2449-
/* Complete "CREATE RULE <sth> AS ON" with SELECT|UPDATE|INSERT|DELETE */
2450-
else if (Matches("CREATE", "RULE", MatchAny, "AS", "ON"))
2461+
/* Complete "CREATE [ OR REPLACE ] RULE <sth> AS ON" with SELECT|UPDATE|INSERT|DELETE */
2462+
else if (Matches("CREATE", "RULE", MatchAny, "AS", "ON") ||
2463+
Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS", "ON"))
24512464
COMPLETE_WITH("SELECT", "UPDATE", "INSERT", "DELETE");
24522465
/* Complete "AS ON SELECT|UPDATE|INSERT|DELETE" with a "TO" */
24532466
else if (TailMatches("AS", "ON", "SELECT|UPDATE|INSERT|DELETE"))
@@ -2726,11 +2739,13 @@ psql_completion(const char *text, int start, int end)
27262739
}
27272740

27282741
/* CREATE VIEW --- is allowed inside CREATE SCHEMA, so use TailMatches */
2729-
/* Complete CREATE VIEW <name> with AS */
2730-
else if (TailMatches("CREATE", "VIEW", MatchAny))
2742+
/* Complete CREATE [ OR REPLACE ] VIEW <name> with AS */
2743+
else if (TailMatches("CREATE", "VIEW", MatchAny) ||
2744+
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny))
27312745
COMPLETE_WITH("AS");
2732-
/* Complete "CREATE VIEW <sth> AS with "SELECT" */
2733-
else if (TailMatches("CREATE", "VIEW", MatchAny, "AS"))
2746+
/* Complete "CREATE [ OR REPLACE ] VIEW <sth> AS with "SELECT" */
2747+
else if (TailMatches("CREATE", "VIEW", MatchAny, "AS") ||
2748+
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "AS"))
27342749
COMPLETE_WITH("SELECT");
27352750

27362751
/* CREATE MATERIALIZED VIEW */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy