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 1nV9fX-0007GK-F4 for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Mar 2022 10:17:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nV9fU-0003Fb-Fz for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Mar 2022 10:17:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nV9fT-0003FS-1a for pgsql-hackers@lists.postgresql.org; Fri, 18 Mar 2022 10:17:12 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nV9fP-0003bm-41 for pgsql-hackers@lists.postgresql.org; Fri, 18 Mar 2022 10:17:10 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 0597A3201FDE; Fri, 18 Mar 2022 06:17:02 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 18 Mar 2022 06:17:03 -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=0bz/a5+dmwHhgNvJXHsaSHI6h0TfIEhn+VhbUO b12Uk=; b=SzWWhrBLsPBX5u4eq16ijLZyKxhNHFg3yed7PHiiwo1KozMfBh7k8n vQXCkV1HDPhH0T82bnpweKlGMvSoDR2dlHIulzjpdya98HoZSZjDoYUEqJTXlLdm 1kYRMbPz+aIPaOEIUp+7FMUjm9h70FEUjgXB+18ILB/aRWdOvrptS/30ybtKcQE4 99LQCfErGd4p3Wc1CtJe0fkKk+Z54lKlF5wY4pzrKpOXV7FdGfnSLHPMiCgBj//t F4i5/FGEh77S8JdXa1a823SL5BNjXg6j5wXXMDApoTKP1lO2+SD9fE4Mh6EJ+sbg 4OTgyYN3rJ2vD/RgdPFNIZ0c6NFcsYqw== 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=0bz/a5+dmwHhgNvJX HsaSHI6h0TfIEhn+VhbUOb12Uk=; b=aaDq7KrM+88EuiHXD1jihGDv65BVqbpRM IZ/cmkZXxP8egpimczQ8BIr2UJTlHV0BVRm4CLsoQKlFztLJYihaMupmDJ9Zjhzz t5S8wNvPDumD3iDsn5HBsz97sTumBBkP8Oh+ItlySpXUh7CS9asx+kQ0dpSac913 IM7PGv2xsdU1Gux9uCJeIbSY8ep/15uCNM+Z4sTfxuG+kzGk/kpcSAdy1OS0/O9u U2G5qYIA/7r2OkD6w3DAE8zXItsknr7ZlKr7c39XjmYd2OpzJReurfnWEcpvraPT y5mSajjThdfWki5dIHM6eeknbkExqAQY8wxdnQmuTQXJAgzD7HRfw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudefiedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufhffjgfkfgggtgesmhdtre ertderjeenucfhrhhomhepffgrghhfihhnnhgpkfhlmhgrrhhipgforghnnhhsnohkvghr uceoihhlmhgrrhhisehilhhmrghrihdrohhrgheqnecuggftrfgrthhtvghrnhepteevie ehteetleeglefghfefkeejheelledttedtgfdvkeffheffvdekheeuudffnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhlmhgrrhhisehilh hmrghrihdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Mar 2022 06:17:01 -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> <87czikrtc1.fsf@wibble.ilmari.org> Date: Fri, 18 Mar 2022 10:17:00 +0000 In-Reply-To: <87czikrtc1.fsf@wibble.ilmari.org> ("Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker=22's?= message of "Fri, 18 Mar 2022 00:35:10 +0000") Message-ID: <87a6dnsgyr.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; charset=utf-8 Content-Transfer-Encoding: 8bit Dagfinn Ilmari Mannsåker writes: > Tom Lane writes: > >> 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 just realised there's no point in the subselect when I'm not applying the same function in the WHERE and the SELECT, so here's an updated version that simplifies that. It also fixes a typo in the commit message. - ilmari --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v4-0001-Add-tab-completion-for-SET-TimeZone-TO.patch From ad4f37359852fa08ec377d86f0bad5f23dff3a0b 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 v4] =?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 the names case-insensitively for convenience, but return them in the original case for legibility. --- src/bin/psql/tab-complete.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 17172827a9..c985781b27 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,16 @@ 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 pg_catalog.quote_literal(name) AS name "\ +" FROM pg_catalog.pg_timezone_names() "\ +" 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 +4194,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 --=-=-=--