From 3663eb0b5008d632972d4b66a105fc08cfff13fb Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Mon, 7 Aug 2023 20:37:19 +0200 Subject: [PATCH v3] psql: Add tab-complete for optional view parameters This adds them in the same matter as it works for storage parameters of tables. Signed-off-by: Christoph Heiss --- src/bin/psql/tab-complete.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 779fdc90cb..83ec1508bb 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1329,6 +1329,13 @@ static const char *const table_storage_parameters[] = { NULL }; +/* Optional parameters for CREATE VIEW and ALTER VIEW */ +static const char *const view_optional_parameters[] = { + "check_option", + "security_barrier", + "security_invoker", + NULL +}; /* Forward declaration of functions */ static char **psql_completion(const char *text, int start, int end); @@ -2216,8 +2223,7 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH("TO"); /* ALTER VIEW */ else if (Matches("ALTER", "VIEW", MatchAny)) - COMPLETE_WITH("ALTER COLUMN", "OWNER TO", "RENAME", - "SET SCHEMA"); + COMPLETE_WITH("ALTER COLUMN", "OWNER TO", "RENAME", "RESET (", "SET"); /* ALTER VIEW xxx RENAME */ else if (Matches("ALTER", "VIEW", MatchAny, "RENAME")) COMPLETE_WITH_ATTR_PLUS(prev2_wd, "COLUMN", "TO"); @@ -2233,6 +2239,16 @@ psql_completion(const char *text, int start, int end) /* ALTER VIEW xxx RENAME COLUMN yyy */ else if (Matches("ALTER", "VIEW", MatchAny, "RENAME", "COLUMN", MatchAnyExcept("TO"))) COMPLETE_WITH("TO"); + /* ALTER VIEW xxx SET ( yyy [= zzz] ) */ + else if (Matches("ALTER", "VIEW", MatchAny, "SET")) + COMPLETE_WITH("(", "SCHEMA"); + /* ALTER VIEW xxx SET|RESET ( yyy [= zzz] ) */ + else if (Matches("ALTER", "VIEW", MatchAny, "SET|RESET", "(")) + COMPLETE_WITH_LIST(view_optional_parameters); + else if (Matches("ALTER", "VIEW", MatchAny, "SET", "(", "check_option", "=")) + COMPLETE_WITH("local", "cascaded"); + else if (Matches("ALTER", "VIEW", MatchAny, "SET", "(", "security_barrier|security_invoker", "=")) + COMPLETE_WITH("true", "false"); /* ALTER MATERIALIZED VIEW */ else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny)) @@ -3525,13 +3541,23 @@ psql_completion(const char *text, int start, int end) } /* CREATE VIEW --- is allowed inside CREATE SCHEMA, so use TailMatches */ - /* Complete CREATE [ OR REPLACE ] VIEW with AS */ + /* Complete CREATE [ OR REPLACE ] VIEW with AS or WITH ( */ else if (TailMatches("CREATE", "VIEW", MatchAny) || TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny)) + COMPLETE_WITH("AS", "WITH ("); + /* Complete CREATE [ OR REPLACE ] VIEW WITH ( with supported options */ + else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(") || + TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(")) + COMPLETE_WITH_LIST(view_optional_parameters); + /* Complete CREATE [ OR REPLACE ] VIEW WITH ( ... ) with "AS" */ + else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(*)") || + TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(*)")) COMPLETE_WITH("AS"); - /* Complete "CREATE [ OR REPLACE ] VIEW AS with "SELECT" */ + /* Complete "CREATE [ OR REPLACE ] VIEW [ WITH ( ... ) ] AS with "SELECT" */ else if (TailMatches("CREATE", "VIEW", MatchAny, "AS") || - TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "AS")) + TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(*)", "AS") || + TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "AS") || + TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(*)", "AS")) COMPLETE_WITH("SELECT"); /* CREATE MATERIALIZED VIEW */ -- 2.41.0