[PATCH v5 4/5] Improve tab completion for ALTER SYSTEM RESET
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
From: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
To:
Date: 2025-08-08T22:07:39Z
Lists: pgsql-hackers
Only complete variables where sourcefile is `postgresql.conf.auto` in
the data directory.
---
src/bin/psql/tab-complete.in.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index dd334d268ca..60bba212f5e 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -1042,6 +1042,13 @@ static const SchemaQuery Query_for_trigger_of_table = {
" WHERE context != 'internal' "\
" AND pg_catalog.lower(name) LIKE pg_catalog.lower('%s')"
+#define Query_for_list_of_alter_system_reset_vars \
+"SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings " \
+" WHERE sourcefile LIKE pg_catalog.regexp_replace( " \
+" pg_catalog.current_setting('data_directory'), " \
+" '[_%%\\\\]', '\\\\\\&') || '_postgresql.auto.conf' " \
+" AND pg_catalog.lower(name) LIKE pg_catalog.lower('%s')"
+
#define Query_for_list_of_set_vars \
"SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings "\
" WHERE context IN ('user', 'superuser') "\
@@ -2624,8 +2631,10 @@ match_previous_words(int pattern_id,
/* ALTER SYSTEM SET, RESET, RESET ALL */
else if (Matches("ALTER", "SYSTEM"))
COMPLETE_WITH("SET", "RESET");
- else if (Matches("ALTER", "SYSTEM", "SET|RESET"))
- COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_alter_system_set_vars,
+ else if (Matches("ALTER", "SYSTEM", "SET"))
+ COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_alter_system_set_vars);
+ else if (Matches("ALTER", "SYSTEM", "RESET"))
+ COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_alter_system_reset_vars,
"ALL");
else if (Matches("ALTER", "SYSTEM", "SET", MatchAny))
COMPLETE_WITH("TO");
--
2.50.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v5-0005-Improve-tab-completion-for-ALTER-SYSTEM-RESET-for.patch