Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cd34247

Browse files
committed
psql: Add tab completion for view options.
Add support for tab completion of WITH (...) options to CREATE VIEW, and for the corresponding SET/RESET (...) options in ALTER VIEW. Christoph Heiss, reviewed by Melih Mutlu, Vignesh C, Jim Jones, Mikhail Gribkov, David Zhang, Shubham Khanna, and me. Discussion: https://postgr.es/m/a2075c5a-66f9-a564-f038-9ac044b03117@c8h4.io
1 parent a9a8108 commit cd34247

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

src/bin/psql/tab-complete.c

+46-4
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,13 @@ static const char *const table_storage_parameters[] = {
13291329
NULL
13301330
};
13311331

1332+
/* Optional parameters for CREATE VIEW and ALTER VIEW */
1333+
static const char *const view_optional_parameters[] = {
1334+
"check_option",
1335+
"security_barrier",
1336+
"security_invoker",
1337+
NULL
1338+
};
13321339

13331340
/* Forward declaration of functions */
13341341
static char **psql_completion(const char *text, int start, int end);
@@ -2216,8 +2223,7 @@ psql_completion(const char *text, int start, int end)
22162223
COMPLETE_WITH("TO");
22172224
/* ALTER VIEW <name> */
22182225
else if (Matches("ALTER", "VIEW", MatchAny))
2219-
COMPLETE_WITH("ALTER COLUMN", "OWNER TO", "RENAME",
2220-
"SET SCHEMA");
2226+
COMPLETE_WITH("ALTER COLUMN", "OWNER TO", "RENAME", "RESET", "SET");
22212227
/* ALTER VIEW xxx RENAME */
22222228
else if (Matches("ALTER", "VIEW", MatchAny, "RENAME"))
22232229
COMPLETE_WITH_ATTR_PLUS(prev2_wd, "COLUMN", "TO");
@@ -2233,6 +2239,21 @@ psql_completion(const char *text, int start, int end)
22332239
/* ALTER VIEW xxx RENAME COLUMN yyy */
22342240
else if (Matches("ALTER", "VIEW", MatchAny, "RENAME", "COLUMN", MatchAnyExcept("TO")))
22352241
COMPLETE_WITH("TO");
2242+
/* ALTER VIEW xxx RESET ( */
2243+
else if (Matches("ALTER", "VIEW", MatchAny, "RESET"))
2244+
COMPLETE_WITH("(");
2245+
/* Complete ALTER VIEW xxx SET with "(" or "SCHEMA" */
2246+
else if (Matches("ALTER", "VIEW", MatchAny, "SET"))
2247+
COMPLETE_WITH("(", "SCHEMA");
2248+
/* ALTER VIEW xxx SET|RESET ( yyy [= zzz] ) */
2249+
else if (Matches("ALTER", "VIEW", MatchAny, "SET|RESET", "("))
2250+
COMPLETE_WITH_LIST(view_optional_parameters);
2251+
else if (Matches("ALTER", "VIEW", MatchAny, "SET", "(", MatchAny))
2252+
COMPLETE_WITH("=");
2253+
else if (Matches("ALTER", "VIEW", MatchAny, "SET", "(", "check_option", "="))
2254+
COMPLETE_WITH("local", "cascaded");
2255+
else if (Matches("ALTER", "VIEW", MatchAny, "SET", "(", "security_barrier|security_invoker", "="))
2256+
COMPLETE_WITH("true", "false");
22362257

22372258
/* ALTER MATERIALIZED VIEW <name> */
22382259
else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny))
@@ -3531,14 +3552,35 @@ psql_completion(const char *text, int start, int end)
35313552
}
35323553

35333554
/* CREATE VIEW --- is allowed inside CREATE SCHEMA, so use TailMatches */
3534-
/* Complete CREATE [ OR REPLACE ] VIEW <name> with AS */
3555+
/* Complete CREATE [ OR REPLACE ] VIEW <name> with AS or WITH */
35353556
else if (TailMatches("CREATE", "VIEW", MatchAny) ||
35363557
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny))
3537-
COMPLETE_WITH("AS");
3558+
COMPLETE_WITH("AS", "WITH");
35383559
/* Complete "CREATE [ OR REPLACE ] VIEW <sth> AS with "SELECT" */
35393560
else if (TailMatches("CREATE", "VIEW", MatchAny, "AS") ||
35403561
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "AS"))
35413562
COMPLETE_WITH("SELECT");
3563+
/* CREATE [ OR REPLACE ] VIEW <name> WITH ( yyy [= zzz] ) */
3564+
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH") ||
3565+
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH"))
3566+
COMPLETE_WITH("(");
3567+
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(") ||
3568+
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "("))
3569+
COMPLETE_WITH_LIST(view_optional_parameters);
3570+
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(", "check_option") ||
3571+
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(", "check_option"))
3572+
COMPLETE_WITH("=");
3573+
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(", "check_option", "=") ||
3574+
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(", "check_option", "="))
3575+
COMPLETE_WITH("local", "cascaded");
3576+
/* CREATE [ OR REPLACE ] VIEW <name> WITH ( ... ) AS */
3577+
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(*)") ||
3578+
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(*)"))
3579+
COMPLETE_WITH("AS");
3580+
/* CREATE [ OR REPLACE ] VIEW <name> WITH ( ... ) AS SELECT */
3581+
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(*)", "AS") ||
3582+
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(*)", "AS"))
3583+
COMPLETE_WITH("SELECT");
35423584

35433585
/* CREATE MATERIALIZED VIEW */
35443586
else if (Matches("CREATE", "MATERIALIZED"))

0 commit comments

Comments
 (0)