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 1mAsuf-0001lD-1O for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Aug 2021 11:48:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mAsue-0002Zw-1a for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Aug 2021 11:48:48 +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 1mAsuc-0002Zo-Hf for pgsql-hackers@lists.postgresql.org; Tue, 03 Aug 2021 11:48:47 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mAsuZ-00019a-Fm for pgsql-hackers@lists.postgresql.org; Tue, 03 Aug 2021 11:48:45 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 66EF85C0130 for ; Tue, 3 Aug 2021 07:48:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 03 Aug 2021 07:48:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilmari.org; h= from:to:subject:date:message-id:mime-version:content-type; s= fm2; bh=JOWHNY7viwfmhzUVOEA9KkvSQOituXQVUfapwMtR0go=; b=DXsv0HXL xjYpoLCuVHPWYJT4m5TlbFCaSCEg+6y6RGmj3HjfvRhXRB3jtFLe4pnHIQNScVnB e4puvgSOd9UcYvaTbr4Z3V5eXxNg4jxPAHFQIwO5W4M07iAd/yMzw6Pf5qm3zjCk rWkG8WenluumkYp76jDTW2LI7PMJf9leBPzvy6DaIaIqTTUlJdyFCv5SxQ+iqDvY BUWRWH35c3+1r46HtLzg5giuXAB/31ctxtJ+mihdM4XnuKfIMlTFQQu/LIlopjeb uKkfPvrCTg2VDunkiodFRyEUOpsoSViWgX2ZF4JW85vHSDYqG78hpPHF6ffplzRK u+MrK47EZgzZ/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=JOWHNY7viwfmhzUVOEA9KkvSQOitu XQVUfapwMtR0go=; b=MN5hZbaxU2NwU/k6wSEP99Xp0KHVhLG5NZbKmgMNZ6CED LiPQlOrYhnwcEchyiX3l9QdCxpE51EngGf0/URWrgK+DWD2anIv1uY2NQd6MwjqF xYYvGIopjnX9bP8bMHjSCaRaSMqxgyxKcQeKVFFg7PWb7hHZqoaeOmOpfnM2T7Tr 9xQ+44qYK4oOrToiSpi+4fsUGgQpnpIRcoXyyKQCX0HqKBcWenbHGjEydPlpmpi9 KPag8Z6/g4jMCCWM7D7izT0+y2YadK6RiHBWF/yXrV1nOuKrVMbowulHi3ASA4xp UJOGSSVP6EdjOvtMQuui6k84iiUQ9FZ2YsS8xJFzQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrieeggdegudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkfgfgggtsehmtderredtre ejnecuhfhrohhmpehilhhmrghrihesihhlmhgrrhhirdhorhhgucdlffgrghhfihhnnhcu kfhlmhgrrhhiucforghnnhhsnohkvghrmdenucggtffrrghtthgvrhhnpeeliefguddtue fgueethfdvvdduvdetieevvddtgfdtffeivdeivdehieehvdevffenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehilhhmrghrihesihhlmhgrrh hirdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 3 Aug 2021 07:48:40 -0400 (EDT) From: ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) To: pgsql-hackers@lists.postgresql.org Subject: [PATCH] Tab completion for ALTER TABLE =?utf-8?Q?=E2=80=A6?= ADD =?utf-8?Q?=E2=80=A6?= Date: Tue, 03 Aug 2021 12:48:38 +0100 Message-ID: <87bl6ehhpl.fsf@wibble.ilmari.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.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 Hi Hackers, The other day I noticed that there's no tab completion after ALTER TABLE … ADD, so here's a patch. In addition to COLUMN and all the table constraint types, it also completes with the list of unique indexes on the table after ALTER TABLE … ADD … USING INDEX. - ilmari --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-tab-completion-for-ALTER-TABLE-ADD.patch From 231cccd2e84ef6dc2bf41423979efc4e760c013e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Tue, 3 Aug 2021 12:23:07 +0100 Subject: [PATCH] =?UTF-8?q?Add=20tab=20completion=20for=20ALTER=20TABLE=20?= =?UTF-8?q?=E2=80=A6=20ADD=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Complte COLUMN and table constraint types, and list of indexes on the table for ADD (UNQIUE|PRIMARY KEY) USING INDEX. --- src/bin/psql/tab-complete.c | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 064892bade..476a72908f 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -776,6 +776,10 @@ static const SchemaQuery Query_for_list_of_collations = { " and pg_catalog.quote_ident(c1.relname)='%s'"\ " and pg_catalog.pg_table_is_visible(c2.oid)" +#define Query_for_unique_index_of_table \ +Query_for_index_of_table \ +" and i.indisunique" + /* the silly-looking length condition is just to eat up the current word */ #define Query_for_constraint_of_table \ "SELECT pg_catalog.quote_ident(conname) "\ @@ -2023,6 +2027,46 @@ psql_completion(const char *text, int start, int end) "OWNER TO", "SET", "VALIDATE CONSTRAINT", "REPLICA IDENTITY", "ATTACH PARTITION", "DETACH PARTITION", "FORCE ROW LEVEL SECURITY"); + /* ALTER TABLE xxx ADD */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD")) + COMPLETE_WITH("COLUMN", "CONSTRAINT", "CHECK", "UNIQUE", "PRIMARY KEY", + "EXCLUDE", "FOREIGN KEY"); + /* ALTER TABLE xxx ADD CONSTRAINT yyy */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny)) + COMPLETE_WITH("CHECK", "UNIQUE", "PRIMARY KEY", "EXCLUDE", "FOREIGN KEY"); + /* ALTER TABLE xxx ADD (CONSTRAINT yyy)? FOREIGN|PRIMARY */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "FOREIGN|PRIMARY") || + Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "FOREIGN|PRIMARY")) + COMPLETE_WITH("KEY"); + /* ALTER TABLE xxx ADD (CONSTRAINT yyy)? (PRIMARY KEY|UNIQUE) */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "PRIMARY", "KEY") || + Matches("ALTER", "TABLE", MatchAny, "ADD", "UNIQUE") || + Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "PRIMARY", "KEY") || + Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "UNIQUE")) + COMPLETE_WITH("(", "USING INDEX"); + /* ALTER TABLE xxx ADD (CONSTRAINT yyy)? ... USING INDEX */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "PRIMARY", "KEY", "USING", "INDEX")) + { + completion_info_charp = prev6_wd; + COMPLETE_WITH_QUERY(Query_for_unique_index_of_table); + } + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "UNIQUE", "USING", "INDEX")) + { + completion_info_charp = prev5_wd; + COMPLETE_WITH_QUERY(Query_for_unique_index_of_table); + } + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, + "PRIMARY", "KEY", "USING", "INDEX")) + { + completion_info_charp = prev8_wd; + COMPLETE_WITH_QUERY(Query_for_unique_index_of_table); + } + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, + "UNIQUE", "USING", "INDEX")) + { + completion_info_charp = prev7_wd; + COMPLETE_WITH_QUERY(Query_for_unique_index_of_table); + } /* ALTER TABLE xxx ENABLE */ else if (Matches("ALTER", "TABLE", MatchAny, "ENABLE")) COMPLETE_WITH("ALWAYS", "REPLICA", "ROW LEVEL SECURITY", "RULE", -- 2.30.2 --=-=-=--