aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Vondra <tomas.vondra@postgresql.org>2025-02-17 17:49:53 +0100
committerTomas Vondra <tomas.vondra@postgresql.org>2025-02-17 18:12:15 +0100
commit9df8727c5067916580f82da8b249136391de8544 (patch)
tree336fd671dae4c194d60eb83201ef5015f4e57c34
parentfc069a3a6319b5bf40d2f0f1efceae1c9b7a68a8 (diff)
downloadpostgresql-9df8727c5067916580f82da8b249136391de8544.tar.gz
postgresql-9df8727c5067916580f82da8b249136391de8544.zip
Add tab completion for ALTER DATABASE RESET
Currently tab completion for ALTER DATABASE RESET shows a list of all configuration parameters that may be set on a database, 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
-rw-r--r--src/bin/psql/tab-complete.in.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index a9a81ab3c14..18fecd32807 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -1000,6 +1000,15 @@ static const SchemaQuery Query_for_trigger_of_table = {
"SELECT datname FROM pg_catalog.pg_database "\
" WHERE datname LIKE '%s'"
+#define Query_for_list_of_database_vars \
+"SELECT conf FROM ("\
+" SELECT setdatabase, pg_catalog.split_part(unnest(setconfig),'=',1) conf"\
+" FROM pg_db_role_setting "\
+" ) s, pg_database d "\
+" WHERE s.setdatabase = d.oid "\
+" AND conf LIKE '%s'"\
+" AND d.datname LIKE '%s'"
+
#define Query_for_list_of_tablespaces \
"SELECT spcname FROM pg_catalog.pg_tablespace "\
" WHERE spcname LIKE '%s'"
@@ -2320,6 +2329,13 @@ match_previous_words(int pattern_id,
"IS_TEMPLATE", "ALLOW_CONNECTIONS",
"CONNECTION LIMIT");
+ /* ALTER DATABASE <name> RESET */
+ else if (Matches("ALTER", "DATABASE", MatchAny, "RESET"))
+ {
+ set_completion_reference(prev2_wd);
+ COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_database_vars, "ALL");
+ }
+
/* ALTER DATABASE <name> SET TABLESPACE */
else if (Matches("ALTER", "DATABASE", MatchAny, "SET", "TABLESPACE"))
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
@@ -4906,7 +4922,9 @@ match_previous_words(int pattern_id,
/* SET, RESET, SHOW */
/* Complete with a variable name */
- else if (TailMatches("SET|RESET") && !TailMatches("UPDATE", MatchAny, "SET"))
+ else if (TailMatches("SET|RESET") &&
+ !TailMatches("UPDATE", MatchAny, "SET") &&
+ !TailMatches("ALTER", "DATABASE", MatchAny, "RESET"))
COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
"CONSTRAINTS",
"TRANSACTION",