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 1mCTZW-0003Je-G5 for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Aug 2021 21:09:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mCTZV-0004IW-8z for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Aug 2021 21:09:33 +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 1mCTZU-0004IL-IU for pgsql-hackers@lists.postgresql.org; Sat, 07 Aug 2021 21:09:33 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCTZM-00028v-Rh for pgsql-hackers@lists.postgresql.org; Sat, 07 Aug 2021 21:09:31 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 2944E320090D for ; Sat, 7 Aug 2021 17:09:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 07 Aug 2021 17:09:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilmari.org; h= from:to:subject:references:date:in-reply-to:message-id :mime-version:content-type; s=fm2; bh=LfqPL5zFHR8BvPAQ1RHweSZBqh 6rvCQBLbkB39aeDUA=; b=qf5O4vjMPJwFLIrw6lQO6/7FlUerLCUl2Y5+oh+O8A ER4+V9TOrS1ItAc7cD6Td5TIL0He0RFC8zCvXyx1+BMaKoyoYywzpjyULkyBukl3 XkaLxdW8YzQIS6SWkAQhMxrUtnzqXJZu2IMWqIKZ1+OFRye61yW3/T8NTxakttgz NAvLw4XehrmpsyxBcHY0Fn8InCju5qft8THzy1BQjzoqmwCGk+hWZ9TcO76LC00V aMquREViZVSMUivGyEJ4iUvfbvqT2tNe2tqlzCnBTvunrvWG7G0qcKJkamA56gxY NFx1LPkJeF7/FKXuqH1Qsx4nQWObyauJ9j5X9eMc7nsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=LfqPL5 zFHR8BvPAQ1RHweSZBqh6rvCQBLbkB39aeDUA=; b=gYa9v7fMZnbeFrQl+c3uLu tjL7Gwd6TmQ5yzsvos0yiuyzV0BlOw+2lB8IBW3p0Isp+LAhN4qOwBY0GCQBdIOL kbi7UdNeA7dhy1qIpZPtcHfRbV2rO+aNyU+XYfmGoOVG7urayzCz9SNnhFKQGd3V 9mxs4u2qqvWaRWjGe+IlzgUHf88/aTtoDhJn4Ot+dLhzF56vo/ElC3Hd9j+xyP81 bx89IyBBaneHygPijgWmODSQ6rDT9LbSYFPxJD9HFu0720MC+nzeqHKiFYSYldHj x+8VE2GoPerAF2725D72svWORtxthTFWGcxyiHWK5SFM+98LNSnawHvP858pNxeQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrjeefgdduheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufhffjgfkfgggtgesmhdtre ertderjeenucfhrhhomhepihhlmhgrrhhisehilhhmrghrihdrohhrghculdffrghgfhhi nhhnucfklhhmrghrihcuofgrnhhnshonkhgvrhdmnecuggftrfgrthhtvghrnhepvdehfe ffudeigeejgfeuffeukeejvddttefggfdttdevtdegveeutdfhgefhgeffnecuffhomhgr ihhnpehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehilhhmrghrihesihhlmhgrrhhirdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 7 Aug 2021 17:09:21 -0400 (EDT) From: ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) To: pgsql-hackers@lists.postgresql.org Subject: Re: Tab completion for CREATE SCHEMAAUTHORIZATION References: <8735snihmz.fsf@wibble.ilmari.org> <87wnprhlsl.fsf@wibble.ilmari.org> Date: Sat, 07 Aug 2021 22:09:19 +0100 In-Reply-To: <87wnprhlsl.fsf@wibble.ilmari.org> ("Dagfinn Ilmari \=\?utf-8\?Q\?Manns\=C3\=A5ker\=22's\?\= message of "Thu, 15 Jul 2021 12:13:46 +0100") Message-ID: <874kc1gdxc.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 ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes: > ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes: > >> Hi Hackers, >> >> I just noticed there's no tab completion for CREATE SCHEMA >> AUTHORIZATION, nor for anything after CREATE SCHEMA . >> >> Please find attached a patch that adds this. > > Added to the 2021-09 commit fest: https://commitfest.postgresql.org/34/3252/ Here's an updated version that also reduces the duplication between the various role list queries. - ilmari --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v2-0001-Add-tab-completion-for-CREATE-SCHEMA.patch From 52c1fe9900543253510b64e58de24f920d8b0dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Fri, 9 Jul 2021 17:15:00 +0100 Subject: [PATCH v2] Add tab completion for CREATE SCHEMA In passing, reduce duplication between the various role list queries --- src/bin/psql/tab-complete.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 064892bade..adddd45f59 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -758,15 +758,16 @@ static const SchemaQuery Query_for_list_of_collations = { " FROM pg_catalog.pg_roles "\ " WHERE substring(pg_catalog.quote_ident(rolname),1,%d)='%s'" -#define Query_for_list_of_grant_roles \ -" SELECT pg_catalog.quote_ident(rolname) "\ -" FROM pg_catalog.pg_roles "\ -" WHERE substring(pg_catalog.quote_ident(rolname),1,%d)='%s'"\ -" UNION ALL SELECT 'PUBLIC'"\ -" UNION ALL SELECT 'CURRENT_ROLE'"\ +#define Query_for_list_of_schema_roles \ +Query_for_list_of_roles \ " UNION ALL SELECT 'CURRENT_USER'"\ " UNION ALL SELECT 'SESSION_USER'" +#define Query_for_list_of_grant_roles \ +Query_for_list_of_schema_roles \ +" UNION ALL SELECT 'PUBLIC'"\ +" UNION ALL SELECT 'CURRENT_ROLE'" + /* the silly-looking length condition is just to eat up the current word */ #define Query_for_index_of_table \ "SELECT pg_catalog.quote_ident(c2.relname) "\ @@ -2675,6 +2676,19 @@ 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, NULL); +/* CREATE SCHEMA [ ] [ AUTHORIZATION ] */ + else if (Matches("CREATE", "SCHEMA")) + COMPLETE_WITH_QUERY(Query_for_list_of_schemas + " UNION ALL SELECT 'AUTHORIZATION'"); + else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION")) + COMPLETE_WITH_QUERY(Query_for_list_of_schema_roles); + else if (Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION")) + COMPLETE_WITH_QUERY(Query_for_list_of_schema_roles); + else if (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)) -- 2.30.2 --=-=-=--