Skip to content

Commit ca09ef3

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 <[email protected]> Reviewed-by: jian he <[email protected]> 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 dbf5a83 commit ca09ef3

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
@@ -1086,9 +1086,12 @@ Keywords_for_list_of_owner_roles, "PUBLIC"
10861086
" WHERE usename LIKE '%s'"
10871087

10881088
#define Query_for_list_of_user_vars \
1089-
" SELECT pg_catalog.split_part(pg_catalog.unnest(rolconfig),'=',1) "\
1090-
" FROM pg_catalog.pg_roles "\
1091-
" WHERE rolname LIKE '%s'"
1089+
"SELECT conf FROM ("\
1090+
" SELECT rolname, pg_catalog.split_part(pg_catalog.unnest(rolconfig),'=',1) conf"\
1091+
" FROM pg_catalog.pg_roles"\
1092+
" ) s"\
1093+
" WHERE s.conf like '%s' "\
1094+
" AND s.rolname LIKE '%s'"
10921095

10931096
#define Query_for_list_of_access_methods \
10941097
" SELECT amname "\
@@ -2517,7 +2520,10 @@ match_previous_words(int pattern_id,
25172520

25182521
/* ALTER USER,ROLE <name> RESET */
25192522
else if (Matches("ALTER", "USER|ROLE", MatchAny, "RESET"))
2523+
{
2524+
set_completion_reference(prev2_wd);
25202525
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_user_vars, "ALL");
2526+
}
25212527

25222528
/* ALTER USER,ROLE <name> WITH */
25232529
else if (Matches("ALTER", "USER|ROLE", MatchAny, "WITH"))
@@ -5015,7 +5021,7 @@ match_previous_words(int pattern_id,
50155021
/* Complete with a variable name */
50165022
else if (TailMatches("SET|RESET") &&
50175023
!TailMatches("UPDATE", MatchAny, "SET") &&
5018-
!TailMatches("ALTER", "DATABASE", MatchAny, "RESET"))
5024+
!TailMatches("ALTER", "DATABASE|USER|ROLE", MatchAny, "RESET"))
50195025
COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
50205026
"CONSTRAINTS",
50215027
"TRANSACTION",

0 commit comments

Comments
 (0)