Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hX9OQ-0007aF-Nq for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Jun 2019 19:10:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hX9OP-0007na-Jw for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Jun 2019 19:10:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hX9OP-0007kl-9s for pgsql-hackers@lists.postgresql.org; Sat, 01 Jun 2019 19:10:13 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hX9ON-0003Ne-6d for pgsql-hackers@lists.postgresql.org; Sat, 01 Jun 2019 19:10:12 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 18EB3216CA for ; Sat, 1 Jun 2019 15:10:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 01 Jun 2019 15:10:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:subject:message-id:mime-version:content-type; s= fm1; bh=f527aVpjiPJcA1PfVijv1u7pQ6SMdehzgiJ2+iCALrk=; b=TQchLTrf t4Uki2FPuytDYNF0/KGAFPQNNlJnVZP8jP/tKaNJrInyWNv8zrFA7qfjUSBa6jq4 nsCosRvP7emsxhmQjyMNlu39rKvqFiUAv1K8csw87c/xZBaO3MqHz0Fg7vykmPKc VgKgi5FQeFgru63NEYV6jJKQA3fgnc5EM62InRUCGExG3Og4sGhLJpO/UTzf2Icr yw+9DHMNZi8kLAYv9QBPnW2+xn/myWP7b1qVkL2mXKY/e9U82FGKICW8dUxoHU3M fkjBbfq+b6+I2krL7ig9254ZmiLoebiJzkhjd5htDzNk4XiNyq/ZCNTKaFJr8vpQ cQsbIgJvH+R4Fw== 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=fm2; bh=f527aVpjiPJcA1PfVijv1u7pQ6SMd ehzgiJ2+iCALrk=; b=UucNEmTvzF+g3aYjiXPnTFkbtVcumIZ5eQjlEptVjQ/qp KOcdLhxWfu+1Im85wXYgda4AHamSzQo2mrZyZ5jJZN7MfPCgtJhIs088IgkjeQqD RkcAY4h9+nLkDUJfKSK2N7eJLDm6yK+cIXWA4aMYc1CF6+6xFxI5E35sxLzkKaJ1 TDpajlX4DhaIL7Xk/DcL8PslRY5ICwC3SsQSvtG9+WVrTHg/FFs8rllVDWd3UMSP 51NaHqg5WZ7sx6X/dwhC8xMlnKwpEaxVvxZim70l6XV4cEYn7rxcBMSa63hAy9mg 6xhzWezgkJEZ37bibHrEnkpTmTnhKvGGa0NiHynwA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrudeffedgudefjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enfghrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfggtggusehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecukfhppedvtdegrddvfeelrddvhedurdehudenucfrrghrrghm pehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlhhush htvghrufhiiigvpedv X-ME-Proxy: Received: from paquier.xyz (unknown [204.239.251.51]) by mail.messagingengine.com (Postfix) with ESMTPA id 7347280059 for ; Sat, 1 Jun 2019 15:10:09 -0400 (EDT) Date: Sat, 1 Jun 2019 15:10:07 -0400 From: Michael Paquier To: Postgres hackers Subject: psql completion bugs with access methods Message-ID: <20190601191007.GC1905@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="LSp5EJdfMPwZcMS1" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --LSp5EJdfMPwZcMS1 Content-Type: multipart/mixed; boundary="8nsIa27JVQLqB7/C" Content-Disposition: inline --8nsIa27JVQLqB7/C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, I have bumped into a couple of issues with psql completion for access methods: 1) CREATE INDEX USING suggests both index and table AMs. 2) CREATE TABLE USING has no completion support, USING not being included in the completion, and the follow-up table AMs are missing as well. 3) CREATE ACCESS METHOD TYPE suggests only INDEX. Attached is a patch to close the gap. Thoughts? -- Michael --8nsIa27JVQLqB7/C Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="ams-completion-v1.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index c6347b6190..5e38f46399 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -41,6 +41,7 @@ =20 #include =20 +#include "catalog/pg_am_d.h" #include "catalog/pg_class_d.h" =20 #include "libpq-fe.h" @@ -824,6 +825,18 @@ static const SchemaQuery Query_for_list_of_statistics = =3D { " FROM pg_catalog.pg_am "\ " WHERE substring(pg_catalog.quote_ident(amname),1,%d)=3D'%s'" =20 +#define Query_for_list_of_index_access_methods \ +" SELECT pg_catalog.quote_ident(amname) "\ +" FROM pg_catalog.pg_am "\ +" WHERE substring(pg_catalog.quote_ident(amname),1,%d)=3D'%s' AND "\ +" amtype=3D" CppAsString2(AMTYPE_INDEX) + +#define Query_for_list_of_table_access_methods \ +" SELECT pg_catalog.quote_ident(amname) "\ +" FROM pg_catalog.pg_am "\ +" WHERE substring(pg_catalog.quote_ident(amname),1,%d)=3D'%s' AND "\ +" amtype=3D" CppAsString2(AMTYPE_TABLE) + /* the silly-looking length condition is just to eat up the current word */ #define Query_for_list_of_arguments \ "SELECT pg_catalog.oidvectortypes(proargtypes)||')' "\ @@ -2234,7 +2247,7 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH("TYPE"); /* Complete "CREATE ACCESS METHOD TYPE" */ else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE")) - COMPLETE_WITH("INDEX"); + COMPLETE_WITH("INDEX", "TABLE"); /* Complete "CREATE ACCESS METHOD TYPE " */ else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE", MatchAny= )) COMPLETE_WITH("HANDLER"); @@ -2322,7 +2335,7 @@ psql_completion(const char *text, int start, int end) else if (TailMatches("INDEX", MatchAny, MatchAny, "ON", MatchAny, "USING"= ) || TailMatches("INDEX", MatchAny, "ON", MatchAny, "USING") || TailMatches("INDEX", "ON", MatchAny, "USING")) - COMPLETE_WITH_QUERY(Query_for_list_of_access_methods); + COMPLETE_WITH_QUERY(Query_for_list_of_index_access_methods); else if (TailMatches("ON", MatchAny, "USING", MatchAny) && !TailMatches("POLICY", MatchAny, MatchAny, MatchAny, MatchAny, MatchAn= y) && !TailMatches("FOR", MatchAny, MatchAny, MatchAny)) @@ -2490,10 +2503,14 @@ psql_completion(const char *text, int start, int en= d) /* Complete CREATE TABLE name (...) with supported options */ else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)") || TailMatches("CREATE", "UNLOGGED", "TABLE", MatchAny, "(*)")) - COMPLETE_WITH("INHERITS (", "PARTITION BY", "TABLESPACE", "WITH ("); + COMPLETE_WITH("INHERITS (", "PARTITION BY", "USING", "TABLESPACE", "WITH= ("); else if (TailMatches("CREATE", "TEMP|TEMPORARY", "TABLE", MatchAny, "(*)"= )) COMPLETE_WITH("INHERITS (", "ON COMMIT", "PARTITION BY", "TABLESPACE", "WITH ("); + /* Complete CREATE TABLE (...) USING with table access methods */ + else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "USING") || + TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(= *)", "USING")) + COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods); /* Complete CREATE TABLE (...) WITH with storage parameters */ else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "WITH", "(") || TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(= *)", "WITH", "(")) --8nsIa27JVQLqB7/C-- --LSp5EJdfMPwZcMS1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlzyzY8ACgkQnvQgOdby QH25uA/9FSkLjzKY//ahMh2MJxCmp4aw2L0bypH80NH50Q3kECivjQ7aRvNngOfg L0pA5OqPOI6vD4TP/6h29hz1dwm2py5ASbgEFJvRNMZoo9BGxsRFkHk9EzWcZ8ZL K/EJCU6EfGdTH0ppyVEtulkaSlr9uhcuvby1GxHYfgujGZw8QwCI0tGDOQAhjk65 FagpLuZXtCkopzAiNNfllEe+k3GjPAmabN2i0iZU5Hkk7dD2nLA54HwXY11Lfpj5 o1G3wEAFGs05xoTSCXmAUfHr5XXnEif+Mx3wLPymZrJy57ZD1MZ/594FEv2ptQm6 MSEj4CpXPgR5kM3IUK9ryg3T/bxgbs4tEKlunc0UPNAlmQb19xijwIA0wl6PYcir 1lWAcl1yKL+rydqtWR8W4hTh/U3p1Ktnmj1JC1w6oOzSbMmtjhMx1BuwroOKMc4j E++zdnmpvTw1ZXgsalWVE0E3ora2q7kn0aIB2UVxsJdqLVC9e2tNFTAQU9/3tmRU mnx6WaNWd1+7wzaxwXkpN2WoM3DUdFezpGIpHaneanYA7o6i21dSr+JT7PfGmMJA Uu+aal+rZ7J8XMUyOPkF+jDIHe7wzYPTCvT9c8yHzr3phxhfdagPswaOoS+KG6iO QYn/1mOmz2et3vVOyegqnnGxxWcKmEuWrokPJlVwRGAboRU20Yo= =jkzU -----END PGP SIGNATURE----- --LSp5EJdfMPwZcMS1--