Tab completion for SET TimeZone

Поиск
Список
Период
Сортировка
От Dagfinn Ilmari Mannsåker
Тема Tab completion for SET TimeZone
Дата
Msg-id 87k0curq0w.fsf@wibble.ilmari.org
обсуждение исходный текст
Ответы Re: Tab completion for SET TimeZone  (Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>)
Список pgsql-hackers
Hi hackers,

I noticed there was no tab completion for time zones in psql, so here's
a patch that implements that.  I chose lower-casing the names since they
are case insensitive, and verbatim since ones without slashes can be
entered without quotes, and (at least my version of) readline completes
them correctly if the entered value starts with a single quote.

- ilmari

From 96ce5843641d990b278c0038f5b97941df6e73a9 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] =?UTF-8?q?Add=20tab=20completion=20for=20SET=20TimeZone?=
 =?UTF-8?q?=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..58e62a5e6e 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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Aleksander Alekseev
Дата:
Сообщение: Re: ExecTypeSetColNames is fundamentally broken
Следующее
От: Dagfinn Ilmari Mannsåker
Дата:
Сообщение: Re: Tab completion for SET TimeZone