Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> writes:
> Hi hackers,
>
> I noticed there was no tab completion for time zones in psql, so here's
> a patch that implements that.
I just noticed I left out the = in the match check, here's an updated
patch that fixes that.
- ilmari
From bcfa40ff3a6702e1bd7112eeaecfde87efaa43c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Wed, 16 Mar 2022 12:52:21 +0000
Subject: [PATCH v2] =?UTF-8?q?Add=20tab=20completion=20for=20SET=20TimeZon?=
=?UTF-8?q?e=20TO=20=E2=80=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Using verbatim and lower-case for maximum convenience.
---
src/bin/psql/tab-complete.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 17172827a9..d68d001085 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1105,6 +1105,13 @@ static const SchemaQuery Query_for_trigger_of_table = {
" FROM pg_catalog.pg_cursors "\
" WHERE name LIKE '%s'"
+#define Query_for_list_of_timezones \
+" SELECT name FROM ("\
+" SELECT pg_catalog.lower(name) AS name "\
+" FROM pg_catalog.pg_timezone_names() "\
+" ) ss "\
+" WHERE name LIKE '%s'"
+
/*
* These object types were introduced later than our support cutoff of
* server version 9.2. We use the VersionedQuery infrastructure so that
@@ -4171,6 +4178,8 @@ psql_completion(const char *text, int start, int end)
" AND nspname NOT LIKE E'pg\\\\_temp%%'",
"DEFAULT");
}
+ else if (TailMatches("TimeZone", "TO|="))
+ COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_timezones, "DEFAULT");
else
{
/* generic, type based, GUC support */
--
2.30.2