Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nV0aO-0001wc-VD for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Mar 2022 00:35:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nV0aN-00008x-6W for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Mar 2022 00:35:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nV0aM-00008n-CZ for pgsql-hackers@lists.postgresql.org; Fri, 18 Mar 2022 00:35:18 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nV0aJ-0005l2-Bn for pgsql-hackers@lists.postgresql.org; Fri, 18 Mar 2022 00:35:17 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 546C15C0252; Thu, 17 Mar 2022 20:35:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 17 Mar 2022 20:35:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilmari.org; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; bh=MK49JolFWnp95KAdyU5RvQnNFdjMUt8NK7vu9X iXtIs=; b=pipMjGk3VUflOdcJWFCScEuoMAXeaoEZ5JWEOnpB8mamp1ciNdwD0Z oDyFIsI1WfXiOfrCRFtRLmjKHGgXcamG4xt/0vo+5yqhtwOfZFmwSBAjW1M7QoEo +YZj6/M8wHLdJMmOGlkobRD99zctOD5bS1xP7yLdrmY37OwXkgpfq2WzbJ99mNpS gPgz1xCvnC94ozojJzPuoQy2JgdWrup353Ls+aZNIDvnivHnoUdyB9nGcwP1VoLC 7T1kxR+VeMKg6NSiqfj9QLkFY9Lj/RECS7VYayNGvm5602RfQk+9mwIlgPW6TgBu XEWm0+9ZSdWBhGpri+svOHwU7xsYhsxg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=MK49JolFWnp95KAdy U5RvQnNFdjMUt8NK7vu9XiXtIs=; b=Zl+WPz/QXFFWi15o6sucMS37acU2pw3wt iZtHpJ9m01TuvtpI/E0MAoYZgKPt9Z0GpBVJfbDRt06kg7OVqOMb1et7+4E6z0M2 dVJQq3NmaVZ0ij19tSGfHwsTRaYxbOfm4LE/IHVpBoCtmT6CKIcVjteeWzNvqxGI qOpWi1WzELdGUwHvqEXn0KLEJdYuaKX6bnnFFSqotnkxqsvLNuFrKTdKUYZeU08T Mj6PN/Xg1iokWxQPqAH565k/uXfPkKTb78QUu8ePCIXZXxLX3gMs0PGR+nA/V1hV JXLbqr9NqdAirrgywP1Jr9qlFXOrE8xIS/M1j2YVAi9fUwbA4g5Rg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudefhedgvdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufhffjgfkfgggtgesmhdtre ertderjeenucfhrhhomhepffgrghhfihhnnhgpkfhlmhgrrhhipgforghnnhhsnohkvghr uceoihhlmhgrrhhisehilhhmrghrihdrohhrgheqnecuggftrfgrthhtvghrnhepteevie ehteetleeglefghfefkeejheelledttedtgfdvkeffheffvdekheeuudffnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhlmhgrrhhisehilh hmrghrihdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 17 Mar 2022 20:35:12 -0400 (EDT) From: =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Tab completion for SET TimeZone References: <87k0curq0w.fsf@wibble.ilmari.org> <87h77yrpsu.fsf@wibble.ilmari.org> <514658.1647438049@sss.pgh.pa.us> Date: Fri, 18 Mar 2022 00:35:10 +0000 In-Reply-To: <514658.1647438049@sss.pgh.pa.us> (Tom Lane's message of "Wed, 16 Mar 2022 09:40:49 -0400") Message-ID: <87czikrtc1.fsf@wibble.ilmari.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain Tom Lane writes: > =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= writes: >> I just noticed I left out the = in the match check, here's an updated >> patch that fixes that. > > Hmm .... is that actually going to be useful in that form? > Most time zone names contain slashes and will therefore require > single-quoting. I think you might need pushups comparable to > COMPLETE_WITH_ENUM_VALUE. With readline (which is what I tested on) the completion works with or without a single quote, but the user has to supply the quote themselves for non-identifier-syntax timezone names. I wasn't aware of the difference in behaviour with libedit, but now that I've tested I agree that quoting things even when not strictly needed is better. This does however have the unfortunate side effect that on readline it will suggest DEFAULT even after a single quote, which is not valid. > Also, personally, I'd rather not smash the names to lower case. > I think that's a significant decrement of readability. That was mainly for convenience of not having to capitalise the place names when typing (since they are accepted case insensitively). A compromise would be to lower-case it in the WHERE, but not in the SELECT, as in the attached v3 patch. I've tested this version on Debian stable with both readline 8.1-1 and libedit 3.1-20191231-2. - ilmari --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v3-0001-Add-tab-completion-for-SET-TimeZone-TO.patch From 07ed215e983fe4fda10cf92ddd12991f76e1410d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Wed, 16 Mar 2022 12:52:21 +0000 Subject: [PATCH v3] =?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 Because the value (usually) needs single-quoting, and libedit includes the leading quote in the text passed to the tab completion, but readline doesn't, handle it simlarly to what we do for enum values. This does however mean that under readline it'll include DEFAULT even after an opening single quote, which is not valid. Match then names case-insensitively for convenience, but return them in the original case for legibility. --- src/bin/psql/tab-complete.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 17172827a9..bb2e6f47a7 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -402,6 +402,19 @@ do { \ matches = rl_completion_matches(text, complete_from_schema_query); \ } while (0) +#define COMPLETE_WITH_TIMEZONE_NAME() \ +do { \ + static const char *const list[] = { "DEFAULT", NULL }; \ + if (text[0] == '\'' || \ + start == 0 || rl_line_buffer[start - 1] != '\'') \ + completion_charp = Query_for_list_of_timezone_names_quoted; \ + else \ + completion_charp = Query_for_list_of_timezone_names_unquoted; \ + completion_charpp = list; \ + completion_verbatim = true; \ + matches = rl_completion_matches(text, complete_from_query); \ +} while (0) + #define COMPLETE_WITH_FUNCTION_ARG(function) \ do { \ set_completion_reference(function); \ @@ -1105,6 +1118,18 @@ static const SchemaQuery Query_for_trigger_of_table = { " FROM pg_catalog.pg_cursors "\ " WHERE name LIKE '%s'" +#define Query_for_list_of_timezone_names_unquoted \ +" SELECT name "\ +" FROM pg_catalog.pg_timezone_names() "\ +" WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')" + +#define Query_for_list_of_timezone_names_quoted \ +" SELECT name FROM ("\ +" SELECT pg_catalog.quote_literal(name) AS name "\ +" FROM pg_catalog.pg_timezone_names() "\ +" ) ss "\ +" WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%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 +4196,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_TIMEZONE_NAME(); else { /* generic, type based, GUC support */ -- 2.30.2 --=-=-=--