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

Commit 49917db

Browse files
committed
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>
1 parent f9d747a commit 49917db

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/bin/psql/tab-complete.c

+21
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,13 @@ static const SchemaQuery Query_for_list_of_matviews = {
820820
" WHERE (%d = pg_catalog.length('%s'))"\
821821
" AND pg_catalog.quote_ident(name)='%s'"
822822

823+
/* the silly-looking length condition is just to eat up the current word */
824+
#define Query_for_list_of_available_extension_versions_with_TO \
825+
" SELECT 'TO ' || pg_catalog.quote_ident(version) "\
826+
" FROM pg_catalog.pg_available_extension_versions "\
827+
" WHERE (%d = pg_catalog.length('%s'))"\
828+
" AND pg_catalog.quote_ident(name)='%s'"
829+
823830
#define Query_for_list_of_prepared_statements \
824831
" SELECT pg_catalog.quote_ident(name) "\
825832
" FROM pg_catalog.pg_prepared_statements "\
@@ -1414,6 +1421,20 @@ psql_completion(const char *text, int start, int end)
14141421
else if (Matches3("ALTER", "EXTENSION", MatchAny))
14151422
COMPLETE_WITH_LIST4("ADD", "DROP", "UPDATE", "SET SCHEMA");
14161423

1424+
/* ALTER EXTENSION <name> UPDATE */
1425+
else if (Matches4("ALTER", "EXTENSION", MatchAny, "UPDATE"))
1426+
{
1427+
completion_info_charp = prev2_wd;
1428+
COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions_with_TO);
1429+
}
1430+
1431+
/* ALTER EXTENSION <name> UPDATE TO */
1432+
else if (Matches5("ALTER", "EXTENSION", MatchAny, "UPDATE", "TO"))
1433+
{
1434+
completion_info_charp = prev3_wd;
1435+
COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions);
1436+
}
1437+
14171438
/* ALTER FOREIGN */
14181439
else if (Matches2("ALTER", "FOREIGN"))
14191440
COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE");

0 commit comments

Comments
 (0)