postgres.git / summary / log / commit / refs
commit 49917dbd76ba0b4179a82fcf033ef5a10b8e3488
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu Aug 18 15:17:10 2016 +0000
First released in: 10.0
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: <CAMkU=1z0gxEOLg2BWa69P4X4Ot8xBxipGUiGkXe_tC+raj79-Q@mail.gmail.com>
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 8469d9ff03d..d31fd25b8d8 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 <name> 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 <name> 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");
[parent: f9d747a4e908]