Skip to content

Commit 8891433

Browse files
committed
Fix tab completion for ALTER ROLE|USER ... RESET
Commit c407d54 added tab completion for ALTER ROLE|USER ... RESET, with the intent to offer only the variables actually set on the role. But as soon as the user started typing something, it would start to offer all possible matching variables. Fix this the same way ALTER DATABASE ... RESET does it, i.e. by properly considering the prefix. A second issue causing similar symptoms (offering variables that are not actually set for a role) was caused by a match to another pattern. The ALTER DATABASE ... RESET was already excluded, so do the same thing for ROLE/USER. Report and fix by Dagfinn Ilmari Mannsåker. Backpatch to 18, same as c407d54. Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> Reviewed-by: jian he <jian.universality@gmail.com> Discussion: https://postgr.es/m/87qzyghw2x.fsf%40wibble.ilmari.org Discussion: https://postgr.es/m/87tt4lumqz.fsf%40wibble.ilmari.org Backpatch-through: 18
1 parent 72c437f commit 8891433

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/bin/psql/tab-complete.in.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,9 +1078,12 @@ Keywords_for_list_of_owner_roles, "PUBLIC"
10781078
" WHERE usename LIKE '%s'"
10791079

10801080
#define Query_for_list_of_user_vars \
1081-
" SELECT pg_catalog.split_part(pg_catalog.unnest(rolconfig),'=',1) "\
1082-
" FROM pg_catalog.pg_roles "\
1083-
" WHERE rolname LIKE '%s'"
1081+
"SELECT conf FROM ("\
1082+
" SELECT rolname, pg_catalog.split_part(pg_catalog.unnest(rolconfig),'=',1) conf"\
1083+
" FROM pg_catalog.pg_roles"\
1084+
" ) s"\
1085+
" WHERE s.conf like '%s' "\
1086+
" AND s.rolname LIKE '%s'"
10841087

10851088
#define Query_for_list_of_access_methods \
10861089
" SELECT amname "\
@@ -2508,7 +2511,10 @@ match_previous_words(int pattern_id,
25082511

25092512
/* ALTER USER,ROLE <name> RESET */
25102513
else if (Matches("ALTER", "USER|ROLE", MatchAny, "RESET"))
2514+
{
2515+
set_completion_reference(prev2_wd);
25112516
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_user_vars, "ALL");
2517+
}
25122518

25132519
/* ALTER USER,ROLE <name> WITH */
25142520
else if (Matches("ALTER", "USER|ROLE", MatchAny, "WITH"))
@@ -4958,7 +4964,7 @@ match_previous_words(int pattern_id,
49584964
/* Complete with a variable name */
49594965
else if (TailMatches("SET|RESET") &&
49604966
!TailMatches("UPDATE", MatchAny, "SET") &&
4961-
!TailMatches("ALTER", "DATABASE", MatchAny, "RESET"))
4967+
!TailMatches("ALTER", "DATABASE|USER|ROLE", MatchAny, "RESET"))
49624968
COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
49634969
"CONSTRAINTS",
49644970
"TRANSACTION",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy