Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ueB11-0061wl-9X for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 11:18:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ueB10-006mdO-4T for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 11:18:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ueB0z-006mdG-Mv for pgsql-hackers@lists.postgresql.org; Tue, 22 Jul 2025 11:18:34 +0000 Received: from fout-b2-smtp.messagingengine.com ([202.12.124.145]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1ueB0x-000C1M-0h for pgsql-hackers@lists.postgresql.org; Tue, 22 Jul 2025 11:18:33 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 751571D0025A; Tue, 22 Jul 2025 07:18:30 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Tue, 22 Jul 2025 07:18:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilmari.org; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1753183110; x=1753269510; bh=aUWZvz0epk tIOCFdo44+5H6kCtT9zSAvxNz4Q3514NE=; b=2W3al4yAGObFv02nP6llXMUTUy rQShGCDMNSh9xxG3NtwoVsbxkBKSPOoKOXGKaRSeiYioCJAUsoBiXIyBPf1TyHwq WBuZoZmp71pvSOI4faQGQK/8ILuhonwAxaE160NRaDcDjTbcYEByqqquONw+uBKJ iHjST0yXt+4IEO7CnDufSuUy440Hu/QKVRlDJ60OCOgfGzd/zac7lgHVFvL1Tn5b fx/XZkiyb7+sLhKk/mdqEdkstUSKO0qbgXO4c29JljW6n53he8dgzEJVyDty+RQv Mu/X3vMh1WF0AnAhpF1fTylDDwUcrgQh9nSrEqccaVr8GCC4ZSm7IOwilj9A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1753183110; x=1753269510; bh=aUWZvz0epktIOCFdo44+5H6kCtT9zSAvxNz 4Q3514NE=; b=bHuzuyIk6nL9Ue+v+idar0iDACgihTYoRqRf1D+auGG778plWIX UyNtoU9Ce1DoEPAIwkYYioQRBv2vruUzgKqdTFuVaAqgfkrdIP9tovapE7AVnlKX o7GxzCVRpVAj7wlH9rWMDdU1rPkXtxjEUpvnRRuYap2iKyXx4rR8gDJBhsBYRP3C 9PQ5MLufYbTohfsZtkg75/fL5Qmcx6Lye+32RUyuvKp3HoYe+FK0CLMYu0CQPOli k0tNJaTHH0tbSjgytja1f/vueFeA0NMkpwg6FMhUzsrr11QVhmq5YXuAuVf+IRSm J9PUdN1GL0jqXx9qBwm0tpRu6wYs9O8jyMw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejgeejhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufgjfhgffffkgggtsehmtderredtreejnecuhfhrohhmpeffrghgfhhinhhn ucfklhhmrghrihcuofgrnhhnshonkhgvrhcuoehilhhmrghrihesihhlmhgrrhhirdhorh hgqeenucggtffrrghtthgvrhhnpeffhfdutddvjedugeefuddvhffggfevueffleevffek ieevtdekuefhtdduteetkeenucffohhmrghinhepphhoshhtghhrrdgvshenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehilhhmrghrihesihhl mhgrrhhirdhorhhgpdhnsggprhgtphhtthhopeegpdhmohguvgepshhmthhpohhuthdprh gtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhq lhdrohhrghdprhgtphhtthhopehtohhmrghsrdhvohhnughrrgesphhoshhtghhrvghsqh hlrdhorhhgpdhrtghpthhtohepthhhrghrrghkrghnsehgmhgrihhlrdgtohhmpdhrtghp thhtohepjhhirghnrdhunhhivhgvrhhsrghlihhthiesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i1ff147bf:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 22 Jul 2025 07:18:28 -0400 (EDT) From: =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= To: jian he , Robins Tharakan , Tomas Vondra Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Fix tab completion in v18 for ALTER DATABASE/USER/ROLE ... RESET In-Reply-To: (jian he's message of "Tue, 22 Jul 2025 18:28:18 +0800") References: <87qzyghw2x.fsf@wibble.ilmari.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Date: Tue, 22 Jul 2025 12:18:28 +0100 Message-ID: <87ecu8iid7.fsf@wibble.ilmari.org> 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 jian he writes: > On Thu, Jul 17, 2025 at 1:41 AM Dagfinn Ilmari Mannsåker > wrote: >> >> Hi hackers, >> >> These two patches are split out from my earlier thread about improving >> tab completion for varous RESET forms >> (https://postgr.es/m/87bjqwwtic.fsf@wibble.ilmari.org), so that the bug >> fixes can be tracked as an open item for v18. >> >> Commits 9df8727c5067 and c407d5426b87 added tab completion for ALTER >> DATABASE ... RESET and ALTER ROLE/USER ... RESET, respectively, but >> they're both differently buggy. The query for the DATABASE form >> neglected to schema-qualify the unnest() call, and the query for the >> ROLE/USER form shows all possible variables once you start typing a >> variable name, not just the ones that are set on the role. The attached >> patches fix both. >> > > I played around with it, and overall it looks good. Thanks for the review. I realise I should have included Robins and Tomas in the original mail, since they were the author and committer, respectively, of the original patches. I've added them now, and reattached the patches for their convenience. - ilmari --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Schema-qualify-unnest-call-in-ALTER-DATABASE-.-RESET.patch From 0dc6058941b5195b58d26ad5baeebc9fb4ca36fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Wed, 11 Jun 2025 13:10:54 +0100 Subject: [PATCH 1/2] Schema-qualify unnest() call in ALTER DATABASE ... RESET tab completion Commit 9df8727c5067 added tab completion for ALTER DATABASE ... RESET, but forgot to schema-qualifiy the unnest() call. --- src/bin/psql/tab-complete.in.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 37524364290..5ca9bc2fc0d 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -1010,7 +1010,7 @@ static const SchemaQuery Query_for_trigger_of_table = { #define Query_for_list_of_database_vars \ "SELECT conf FROM ("\ -" SELECT setdatabase, pg_catalog.split_part(unnest(setconfig),'=',1) conf"\ +" SELECT setdatabase, pg_catalog.split_part(pg_catalog.unnest(setconfig),'=',1) conf"\ " FROM pg_db_role_setting "\ " ) s, pg_database d "\ " WHERE s.setdatabase = d.oid "\ -- 2.50.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Fix-tab-completion-for-ALTER-ROLE-USER-.-RESET.patch From 83bf13c9ea813047d1c462434fe32c54db9b28dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Mon, 9 Jun 2025 20:35:29 +0100 Subject: [PATCH 2/2] Fix tab completion for ALTER ROLE|USER ... RESET Commit c407d5426b87 added tab completion for ALTER ROLE|USER ... RESET, but it was buggy. It showed only the variables set on the role when hitting TAB just after RESET, but as soon as one starts typing something to pick what to complete, it would complete all possible variables, not just the ones set on the role. Fix it in the same way as ALTER DATABASE ... RESET does it. --- src/bin/psql/tab-complete.in.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 5ca9bc2fc0d..257ae55ee32 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -1086,9 +1086,12 @@ Keywords_for_list_of_owner_roles, "PUBLIC" " WHERE usename LIKE '%s'" #define Query_for_list_of_user_vars \ -" SELECT pg_catalog.split_part(pg_catalog.unnest(rolconfig),'=',1) "\ -" FROM pg_catalog.pg_roles "\ -" WHERE rolname LIKE '%s'" +"SELECT conf FROM ("\ +" SELECT rolname, pg_catalog.split_part(pg_catalog.unnest(rolconfig),'=',1) conf"\ +" FROM pg_catalog.pg_roles"\ +" ) s"\ +" WHERE s.conf like '%s' "\ +" AND s.rolname LIKE '%s'" #define Query_for_list_of_access_methods \ " SELECT amname "\ @@ -2516,7 +2519,10 @@ match_previous_words(int pattern_id, /* ALTER USER,ROLE RESET */ else if (Matches("ALTER", "USER|ROLE", MatchAny, "RESET")) + { + set_completion_reference(prev2_wd); COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_user_vars, "ALL"); + } /* ALTER USER,ROLE WITH */ else if (Matches("ALTER", "USER|ROLE", MatchAny, "WITH")) -- 2.50.1 --=-=-=--