Add tab completion for ALTER USER/ROLE RESET
authorTomas Vondra <tomas.vondra@postgresql.org>
Mon, 17 Feb 2025 16:55:23 +0000 (17:55 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Mon, 17 Feb 2025 17:12:15 +0000 (18:12 +0100)
Currently tab completion for ALTER USER RESET shows a list of all
configuration parameters that may be set on a role, irrespectively of
which parameters are actually set. This patch improves tab completion to
offer only parameters that are set.

Author: Robins Tharakan
Reviewed-By: Tomas Vondra
Discussion: https://postgr.es/m/CAEP4nAzqiT6VbVC5r3nq5byLTnPzjniVGzEMpYcnAHQyNzEuaw%40mail.gmail.com

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

index 18fecd3280719fba874c92b660d93795b11055ac..eb8bc12872022442d36d28739f2609f1571b88e7 100644 (file)
@@ -1077,6 +1077,11 @@ Keywords_for_list_of_owner_roles, "PUBLIC"
 "   FROM pg_catalog.pg_user_mappings "\
 "  WHERE usename LIKE '%s'"
 
+#define Query_for_list_of_user_vars \
+" SELECT pg_catalog.split_part(pg_catalog.unnest(rolconfig),'=',1) "\
+"   FROM pg_catalog.pg_roles "\
+"  WHERE rolname LIKE '%s'"
+
 #define Query_for_list_of_access_methods \
 " SELECT amname "\
 "   FROM pg_catalog.pg_am "\
@@ -2487,6 +2492,10 @@ match_previous_words(int pattern_id,
                      "RENAME TO", "REPLICATION", "RESET", "SET", "SUPERUSER",
                      "VALID UNTIL", "WITH");
 
+   /* ALTER USER,ROLE <name> RESET */
+   else if (Matches("ALTER", "USER|ROLE", MatchAny, "RESET"))
+       COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_user_vars, "ALL");
+
    /* ALTER USER,ROLE <name> WITH */
    else if (Matches("ALTER", "USER|ROLE", MatchAny, "WITH"))
        /* Similar to the above, but don't complete "WITH" again. */