From 49917dbd76ba0b4179a82fcf033ef5a10b8e3488 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 18 Aug 2016 11:17:10 -0400 Subject: [PATCH] Improve psql's tab completion for ALTER EXTENSION foo UPDATE ... Offer a list of available versions for that extension. Formerly, since there was no special support for this, it triggered off the UPDATE keyword and offered a list of table names --- not too helpful. Jeff Janes, reviewed by Gerdan Santos Patch: --- src/bin/psql/tab-complete.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 8469d9ff03..d31fd25b8d 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -820,6 +820,13 @@ static const SchemaQuery Query_for_list_of_matviews = { " WHERE (%d = pg_catalog.length('%s'))"\ " AND pg_catalog.quote_ident(name)='%s'" +/* the silly-looking length condition is just to eat up the current word */ +#define Query_for_list_of_available_extension_versions_with_TO \ +" SELECT 'TO ' || pg_catalog.quote_ident(version) "\ +" FROM pg_catalog.pg_available_extension_versions "\ +" WHERE (%d = pg_catalog.length('%s'))"\ +" AND pg_catalog.quote_ident(name)='%s'" + #define Query_for_list_of_prepared_statements \ " SELECT pg_catalog.quote_ident(name) "\ " FROM pg_catalog.pg_prepared_statements "\ @@ -1414,6 +1421,20 @@ psql_completion(const char *text, int start, int end) else if (Matches3("ALTER", "EXTENSION", MatchAny)) COMPLETE_WITH_LIST4("ADD", "DROP", "UPDATE", "SET SCHEMA"); + /* ALTER EXTENSION UPDATE */ + else if (Matches4("ALTER", "EXTENSION", MatchAny, "UPDATE")) + { + completion_info_charp = prev2_wd; + COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions_with_TO); + } + + /* ALTER EXTENSION UPDATE TO */ + else if (Matches5("ALTER", "EXTENSION", MatchAny, "UPDATE", "TO")) + { + completion_info_charp = prev3_wd; + COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions); + } + /* ALTER FOREIGN */ else if (Matches2("ALTER", "FOREIGN")) COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE"); -- 2.40.0