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 1pnLvk-0003Qx-Vn for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Apr 2023 16:05:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pnLul-0007XM-RI for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Apr 2023 16:04:43 +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 1pnLuk-0007X6-Us for pgsql-hackers@lists.postgresql.org; Fri, 14 Apr 2023 16:04:43 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pnLuh-0002K7-Pu for pgsql-hackers@lists.postgresql.org; Fri, 14 Apr 2023 16:04:41 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id A73715C0049; Fri, 14 Apr 2023 12:04:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 14 Apr 2023 12:04:37 -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:sender :subject:subject:to:to; s=fm3; t=1681488277; x=1681574677; bh=11 M8AREJuPZGON1+XfcNJ8i+2cyTcTlkN3lEyA9+AQU=; b=bYRheyF6vuLdCYOn+j N8XYRqcHoCXiZJnUdUDKu1hsvMmiRCmMk0lmByrar1gjNPz5ijvYOix0LfS6IMVi XaMNzry6RkbnCGgXVEgznMypkQ5L97rxQpf3Q3T4bap/IKeI1wtRSz4c0xxJnChJ ZhLXLPMCj/Ie1JwW67/d+G70qvp6Es+XhIOqDNI198rHUHtljbMgO4+xRqQG72e0 l7h4JR3x3bF4L4ysBlPAhjnFmCnZwTizdpFM5fh1M1DWvTgEfEaa7MfPwbBDNm8p 01n3u6uX0kWwarHefgZBfLnKA7tgT9AdfPVuVOXudVFKUhPKXEA1VS6oDvf834yM Yerg== 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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1681488277; x=1681574677; bh=11M8AREJuPZGO N1+XfcNJ8i+2cyTcTlkN3lEyA9+AQU=; b=H5HTLJ87Td0WtYpF2ZiCiZbadqz7g /zluVDqRXwtnKGwEBMibb7XwYhrCpM3HupDiom59WT2G4amOEWUb+MgLzHUBKveM yBo+OWZnILGp8E0QPqx0ESzbwC0bmrdKt8BZm2u4Fard9YlfWZ0t7PHYlyZw2smU N8PfetzGSop3524WReM1rMj8HLjEGP+z3T8JTU2CDSvEb4v5nkBu/JIFksm1jufc +egxbLJmACeNAGDCkUmIFkqW0RpZhI3PQwtOIHKSa0oHSXiEhFUZ1FIMcX+rFM8D V8EJiAMAHfPQCqXHms58vFunBb8DTLUgsXDB6sU/cmGRb3WtwEKsG79xw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeltddgleeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdlfeehmdenucfjughrpefhvfevufhfffgjkfgfgggtsehmtderredt reejnecuhfhrohhmpeffrghgfhhinhhnucfklhhmrghrihcuofgrnhhnshonkhgvrhcuoe hilhhmrghrihesihhlmhgrrhhirdhorhhgqeenucggtffrrghtthgvrhhnpedvvdfhhedt feekudfgtedufeehgffggeejieejheeugfethefggedtleegteetjeenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehilhhmrghrihesihhlmhgr rhhirdhorhhg X-ME-Proxy: Feedback-ID: i1ff147bf:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Apr 2023 12:04:36 -0400 (EDT) From: =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= To: Michael Paquier Cc: Suraj Khamkar , pgsql-hackers@lists.postgresql.org Subject: Re: Tab completion for CREATE SCHEMAAUTHORIZATION References: <8735snihmz.fsf@wibble.ilmari.org> <87wnprhlsl.fsf@wibble.ilmari.org> <874kc1gdxc.fsf@wibble.ilmari.org> <87im0efqhp.fsf@wibble.ilmari.org> Date: Fri, 14 Apr 2023 17:04:35 +0100 In-Reply-To: (Michael Paquier's message of "Fri, 3 Dec 2021 10:19:23 +0900") Message-ID: <87ildyqwks.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 Michael Paquier writes: > On Wed, Aug 11, 2021 at 10:16:15AM +0900, Michael Paquier wrote: >> + else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION")) >> + COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles); >> + else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION")) >> + COMPLETE_WITH_QUERY(Query_for_list_of_owner_roles); >> + else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny)) >> + COMPLETE_WITH("CREATE", "GRANT"); >> + else if (Matches("CREATE", "SCHEMA", MatchAny)) >> + COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT"); >> Looks like you forgot the case "CREATE SCHEMA AUTHORIZATION MatchAny" >> that should be completed by GRANT and CREATE. > > This patch has been waiting on author for more than a couple of weeks, > so I have marked it as returned with feedback in the CF app. Please > feel free to resubmit if you are able to work more on that. Looks like I completely dropped the ball on this one, sorry. Here's a rebased patch which uses the new COMPLETE_WITH_QUERY_PLUS functionality added in commit 02b8048ba5dc36238f3e7c3c58c5946220298d71. - ilmari --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v2-0001-Add-tab-completion-for-CREATE-SCHEMA.patch From 4c4833dfdd2bb01cd35715223433f961e5ec004c Mon Sep 17 00:00:00 2001 From: tanghy Date: Mon, 9 Aug 2021 18:47:12 +0100 Subject: [PATCH v2] Add tab completion for CREATE SCHEMA - AUTHORIZATION both in addition to and after a schema name - list of owner roles after AUTHORIZATION - CREATE and GRANT after any otherwise-complete command --- src/bin/psql/tab-complete.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 5825b2a195..222dd617a2 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1031,9 +1031,13 @@ static const SchemaQuery Query_for_trigger_of_table = { " FROM pg_catalog.pg_roles "\ " WHERE rolname LIKE '%s'" +/* add these to Query_for_list_of_roles in OWNER contexts */ +#define Keywords_for_list_of_owner_roles \ +"CURRENT_ROLE", "CURRENT_USER", "SESSION_USER" + /* add these to Query_for_list_of_roles in GRANT contexts */ #define Keywords_for_list_of_grant_roles \ -"PUBLIC", "CURRENT_ROLE", "CURRENT_USER", "SESSION_USER" +Keywords_for_list_of_owner_roles, "PUBLIC" #define Query_for_all_table_constraints \ "SELECT conname "\ @@ -3154,6 +3158,20 @@ psql_completion(const char *text, int start, int end) else if (TailMatches("AS", "ON", "SELECT|UPDATE|INSERT|DELETE", "TO")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); +/* CREATE SCHEMA [ ] [ AUTHORIZATION ] */ + else if (Matches("CREATE", "SCHEMA")) + COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas, + "AUTHORIZATION"); + else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION") || + Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION")) + COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, + Keywords_for_list_of_owner_roles); + else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION", MatchAny) || + Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny)) + COMPLETE_WITH("CREATE", "GRANT"); + else if (Matches("CREATE", "SCHEMA", MatchAny)) + COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT"); + /* CREATE SEQUENCE --- is allowed inside CREATE SCHEMA, so use TailMatches */ else if (TailMatches("CREATE", "SEQUENCE", MatchAny) || TailMatches("CREATE", "TEMP|TEMPORARY", "SEQUENCE", MatchAny)) @@ -4263,9 +4281,7 @@ psql_completion(const char *text, int start, int end) /* OWNER TO - complete with available roles */ else if (TailMatches("OWNER", "TO")) COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, - "CURRENT_ROLE", - "CURRENT_USER", - "SESSION_USER"); + Keywords_for_list_of_owner_roles); /* ORDER BY */ else if (TailMatches("FROM", MatchAny, "ORDER")) -- 2.39.2 --=-=-=--