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 1uhWtF-000x2L-1Z for pgsql-hackers@arkaria.postgresql.org; Thu, 31 Jul 2025 17:16:25 +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 1uhWtD-002Y5z-RW for pgsql-hackers@arkaria.postgresql.org; Thu, 31 Jul 2025 17:16:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uhWtD-002Y5r-50 for pgsql-hackers@lists.postgresql.org; Thu, 31 Jul 2025 17:16:23 +0000 Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uhWtA-0003cS-2C for pgsql-hackers@postgresql.org; Thu, 31 Jul 2025 17:16:22 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 889591400240 for ; Thu, 31 Jul 2025 13:16:19 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 31 Jul 2025 13:16:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilmari.org; h=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=fm2; t=1753982179; x=1754068579; bh=uCKKTE0TcO jyuuODHpD17S0BIft6Lnsjs4BaCHG2mu0=; b=hzaCoZdnWVi0bttsgxMvLO3GAZ Ds/qmdpf08ZOo+bhei9O4jToS/dqxC/BruL3K0v5brRGPQHXUX6RLcQ6ZeGbZQFL 1zC8CPc8KhjL91Y2swkJ3bcY8wxX6u31xr9kfeasaqnRQ6yRCyROCCZFV1kpMVv/ GMcpnEKGFZ9niN0EN9vpZDbgyjblWfy+XUj1RSHMAl+AeSzMcjmbO0/n8qJolKHk tQep8hQq1b4jwIxbCuQSyO9IAQzLnTMCVPoIzZXXj7lUU2UD7jZRT4t4+oFSYXXo UNxmuVcnXFZGV8YJFGgFq7guGhTgexuhXK1f5FH5ZkLweiiNMvYVb7q4A4Bg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm3; t= 1753982179; x=1754068579; bh=uCKKTE0TcOjyuuODHpD17S0BIft6Lnsjs4B aCHG2mu0=; b=myfOq0qgRweNNLhggdl0k1rWu2a2/+emZGPQ1DhaV7ePbu/12ac dClIeDGKUUye4FyIl/mvIM08JGhDHj9+/9eSWhSdpNPq3tqbfoQKDX0ReRlJ5FPx a04GzUOXoixBGp1sR/5aaVIgnvjqaerJUvFuM/cl89hz/STe3jhW31AFdDfNIUJM EwRA4tSFEI+q+5XZe4dab6jA45nnBCLEokv6M8uyx92P7TTJHJv/drpoDBkytHeG quhkCOSQYCPpswVHL7HYkTHZOqSurIGcMn7bPnl6aXjvDPBf3erFFo7MWsz3mgiy NB2vseXRwbfqr4l8EKEr0n5gi/i37yyXADA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutddufeelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefhvffufhffjgfkfgggtgesmhdtreertd erjeenucfhrhhomhepffgrghhfihhnnhcukfhlmhgrrhhiucforghnnhhsnohkvghruceo ihhlmhgrrhhisehilhhmrghrihdrohhrgheqnecuggftrfgrthhtvghrnhephedugeeike ejheejhfeuleejffetieehuedtieefjedtjeffieevfeekuddtkeejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhlmhgrrhhisehilhhmrg hrihdrohhrghdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghp thhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i1ff147bf:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 31 Jul 2025 13:16:18 -0400 (EDT) From: =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= To: pgsql-hackers@postgresql.org Subject: Re: Improve tab completion for various SET/RESET forms References: <87bjqwwtic.fsf@wibble.ilmari.org> <18691637-2af2-4a2f-9f12-8201c2a88206@eisentraut.org> <871prqwq19.fsf@wibble.ilmari.org> <87tt4lumqz.fsf@wibble.ilmari.org> Date: Thu, 31 Jul 2025 18:16:17 +0100 In-Reply-To: <87tt4lumqz.fsf@wibble.ilmari.org> ("Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker=22's?= message of "Thu, 12 Jun 2025 14:12:52 +0100") Message-ID: <87seicgu1q.fsf@wibble.ilmari.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (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: > I just noticed that in addition to ALTER ROLE ... RESET being buggy, the > ALTER DATABASE ... RESET query doesn't schema-qualify the unnest() call. > Here's an updated patch series that fixes that too. The first two are > bug fixes to features new in 18 and should IMO be committed before > that's released. The rest can wait for 19. Now that Tomas has committed the two bugfixes, here's the rest of the patches rebased over that. - ilmari --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v3-0001-Add-tab-completion-for-ALTER-TABLE-.-ALTER-COLUMN.patch From e9880ce7a786306ba075c795030bb81a240d0452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Mon, 9 Jun 2025 20:39:15 +0100 Subject: [PATCH v3 1/3] Add tab completion for ALTER TABLE ... ALTER COLUMN ... RESET Unlike SET, it only takes parenthesised attribute options. --- src/bin/psql/tab-complete.in.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 1f2ca946fc5..176ae1284be 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -2913,9 +2913,13 @@ match_previous_words(int pattern_id, "STATISTICS", "STORAGE", /* a subset of ALTER SEQUENCE options */ "INCREMENT", "MINVALUE", "MAXVALUE", "START", "NO", "CACHE", "CYCLE"); - /* ALTER TABLE ALTER [COLUMN] SET ( */ - else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "(") || - Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "(")) + /* ALTER TABLE ALTER [COLUMN] RESET */ + else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "RESET") || + Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "RESET")) + COMPLETE_WITH("("); + /* ALTER TABLE ALTER [COLUMN] SET|RESET ( */ + else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET|RESET", "(") || + Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET|RESET", "(")) COMPLETE_WITH("n_distinct", "n_distinct_inherited"); /* ALTER TABLE ALTER [COLUMN] SET COMPRESSION */ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "COMPRESSION") || -- 2.50.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v3-0002-Add-tab-completion-for-ALTER-FOREIGN-TABLE-.-SET.patch From e3e7fe0378af2d04f4c92e3fdc17fccaf2580d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Mon, 9 Jun 2025 20:41:29 +0100 Subject: [PATCH v3 2/3] Add tab completion for ALTER FOREIGN TABLE ... SET The schema is the only thing that can be set for foreign tables. --- src/bin/psql/tab-complete.in.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 176ae1284be..d31f5780727 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -2435,6 +2435,10 @@ match_previous_words(int pattern_id, COMPLETE_WITH("ADD", "ALTER", "DISABLE TRIGGER", "DROP", "ENABLE", "INHERIT", "NO INHERIT", "OPTIONS", "OWNER TO", "RENAME", "SET", "VALIDATE CONSTRAINT"); + else if (Matches("ALTER", "FOREIGN", "TABLE", MatchAny, "SET")) + COMPLETE_WITH("SCHEMA"); + else if (Matches("ALTER", "FOREIGN", "TABLE", MatchAny, "SET", "SCHEMA")) + COMPLETE_WITH_QUERY(Query_for_list_of_schemas); /* ALTER INDEX */ else if (Matches("ALTER", "INDEX")) -- 2.50.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v3-0003-Improve-tab-completion-for-RESET.patch From 6c165b8b42346620a92973e1003db806385f6d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Mon, 9 Jun 2025 20:48:43 +0100 Subject: [PATCH v3 3/3] Improve tab completion for RESET Only complete variables that have been set in the current session, plus the keywords ALL, ROLE and SESSION (which will subsequently be completed with AUTHORIZATION). --- src/bin/psql/tab-complete.in.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index d31f5780727..e3b685ebe10 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -1047,6 +1047,12 @@ static const SchemaQuery Query_for_trigger_of_table = { " WHERE context IN ('user', 'superuser') "\ " AND pg_catalog.lower(name) LIKE pg_catalog.lower('%s')" +#define Query_for_list_of_session_vars \ +"SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings "\ +" WHERE context IN ('user', 'superuser') "\ +" AND source = 'session' "\ +" AND pg_catalog.lower(name) LIKE pg_catalog.lower('%s')" + #define Query_for_list_of_show_vars \ "SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings "\ " WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')" @@ -5027,9 +5033,8 @@ match_previous_words(int pattern_id, /* SET, RESET, SHOW */ /* Complete with a variable name */ - else if (TailMatches("SET|RESET") && - !TailMatches("UPDATE", MatchAny, "SET") && - !TailMatches("ALTER", "DATABASE|USER|ROLE", MatchAny, "RESET")) + else if (TailMatches("SET") && + !TailMatches("UPDATE", MatchAny, "SET")) COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars, "CONSTRAINTS", "TRANSACTION", @@ -5037,6 +5042,12 @@ match_previous_words(int pattern_id, "ROLE", "TABLESPACE", "ALL"); + /* Complete with variables set in the current session */ + else if (Matches("RESET")) + COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_session_vars, + "ALL", + "ROLE", + "SESSION"); else if (Matches("SHOW")) COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_show_vars, "SESSION AUTHORIZATION", -- 2.50.1 --=-=-=--