Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c46qK-0007L9-JU for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Nov 2016 13:53:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1c46qJ-0005In-Uf for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Nov 2016 13:53:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c46qJ-0005IX-30 for pgsql-hackers@postgresql.org; Tue, 08 Nov 2016 13:53:39 +0000 Received: from ping.uio.no ([2001:700:100:570::196]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1c46qF-00021F-2S for pgsql-hackers@postgresql.org; Tue, 08 Nov 2016 13:53:37 +0000 Received: from [2001:700:100:570::211] (helo=dalvik.ping.uio.no ident=Debian-exim) by ping.uio.no with esmtp (Exim 4.72 #1 (Debian)) id 1c46q7-0003Q2-4O; Tue, 08 Nov 2016 14:53:30 +0100 Received: from ilmari by dalvik.ping.uio.no with local (Exim 4.72) (envelope-from ) id 1c46q6-0005kX-IK; Tue, 08 Nov 2016 14:53:26 +0100 From: ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) To: Artur Zakirov Cc: pgsql-hackers Subject: Re: Re: [PATCH] Tab completion for ALTER TYPE =?utf-8?Q?=E2=80=A6?= RENAME VALUE =?utf-8?Q?=E2=80=A6?= References: Date: Tue, 08 Nov 2016 13:53:26 +0000 In-Reply-To: (Artur Zakirov's message of "Sun, 6 Nov 2016 19:48:18 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Exiscan-Spam-Score: -3.7 (---) X-Exiscan-Spam-Report: SpamAssassin 3.3.1 (2010-03-16) on pike.ping.uio.no Score Rule * -5.0 PING_UIO_MAIL_IS_INTERNAL Message has never been outside * 129.240.0.0/16 or 193.157.115.0/24 * 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Pg-Spam-Score: -4.2 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Artur Zakirov writes: > Hello, Hi Artur, > 2016-09-12 16:16 GMT+03:00 Dagfinn Ilmari Mannsåker : >> >> I've added it to the 2016-11 commit fest: >> https://commitfest.postgresql.org/11/795/ >> >> - ilmari > > I've tested your patch. [...] > It seems that the patch can be commited without any fixes. So I marked > it as "Ready for Committer". Thank you very much. I just looked at the patch again and realised the completion of "TO" after RENAME VALUE can be merged with the one for RENAME ATTRIBUTE . Attached is an updated and patch, which only differs from the previous one as follows: $ interdiff 0001-Add-psql-tab-completion-for-ALTER-TYPE-RENAME-VALUE{,-v2}.patch diff -u b/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c --- b/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1918,11 +1918,8 @@ psql_completion(const char *text, int start, int end) /* ALTER TYPE RENAME */ else if (Matches4("ALTER", "TYPE", MatchAny, "RENAME")) COMPLETE_WITH_LIST3("ATTRIBUTE", "TO", "VALUE"); - /* ALTER TYPE xxx RENAME ATTRIBUTE yyy */ - else if (Matches6("ALTER", "TYPE", MatchAny, "RENAME", "ATTRIBUTE", MatchAny)) - COMPLETE_WITH_CONST("TO"); - /* ALTER TYPE xxx RENAME VALUE yyy */ - else if (Matches6("ALTER", "TYPE", MatchAny, "RENAME", "VALUE", MatchAny)) + /* ALTER TYPE xxx RENAME (ATTRIBUTE|VALUE) yyy */ + else if (Matches6("ALTER", "TYPE", MatchAny, "RENAME", "ATTRIBUTE|VALUE", MatchAny)) COMPLETE_WITH_CONST("TO"); /* * If we have ALTER TYPE ALTER/DROP/RENAME ATTRIBUTE, provide list --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-psql-tab-completion-for-ALTER-TYPE-RENAME-VALUE-v2.patch From d8454b66a544d91bf779ca3bfb38d18e4cd504f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Mon, 12 Sep 2016 12:17:37 +0100 Subject: [PATCH] =?UTF-8?q?Add=20psql=20tab=20completion=20for=20ALTER=20T?= =?UTF-8?q?YPE=20=E2=80=A6=20RENAME=20VALUE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modelled on the completion for attributes, tweaked to return string literals intead of identifiers. --- src/bin/psql/tab-complete.c | 58 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index a43bbc5..b556c00 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -202,6 +202,31 @@ do { \ matches = completion_matches(text, complete_from_query); \ } while (0) +#define COMPLETE_WITH_ENUM_VALUE(type) \ +do { \ + char *_completion_schema; \ + char *_completion_type; \ +\ + _completion_schema = strtokx(type, " \t\n\r", ".", "\"", 0, \ + false, false, pset.encoding); \ + (void) strtokx(NULL, " \t\n\r", ".", "\"", 0, \ + false, false, pset.encoding); \ + _completion_type = strtokx(NULL, " \t\n\r", ".", "\"", 0, \ + false, false, pset.encoding); \ + if (_completion_type == NULL)\ + { \ + completion_charp = Query_for_list_of_enum_values; \ + completion_info_charp = type; \ + } \ + else \ + { \ + completion_charp = Query_for_list_of_enum_values_with_schema; \ + completion_info_charp = _completion_type; \ + completion_info_charp2 = _completion_schema; \ + } \ + matches = completion_matches(text, complete_from_query); \ +} while (0) + #define COMPLETE_WITH_FUNCTION_ARG(function) \ do { \ char *_completion_schema; \ @@ -598,6 +623,26 @@ static const SchemaQuery Query_for_list_of_matviews = { " AND (pg_catalog.quote_ident(nspname)='%s' "\ " OR '\"' || nspname || '\"' ='%s') " +#define Query_for_list_of_enum_values \ +"SELECT pg_catalog.quote_literal(enumlabel) "\ +" FROM pg_catalog.pg_enum e, pg_catalog.pg_type t "\ +" WHERE t.oid = e.enumtypid "\ +" AND substring(pg_catalog.quote_literal(enumlabel),1,%d)='%s' "\ +" AND (pg_catalog.quote_ident(typname)='%s' "\ +" OR '\"' || typname || '\"'='%s') "\ +" AND pg_catalog.pg_type_is_visible(t.oid)" + +#define Query_for_list_of_enum_values_with_schema \ +"SELECT pg_catalog.quote_literal(enumlabel) "\ +" FROM pg_catalog.pg_enum e, pg_catalog.pg_type t, pg_catalog.pg_namespace n "\ +" WHERE t.oid = e.enumtypid "\ +" AND n.oid = t.typnamespace "\ +" AND substring(pg_catalog.quote_literal(enumlabel),1,%d)='%s' "\ +" AND (pg_catalog.quote_ident(typname)='%s' "\ +" OR '\"' || typname || '\"'='%s') "\ +" AND (pg_catalog.quote_ident(nspname)='%s' "\ +" OR '\"' || nspname || '\"' ='%s') " + #define Query_for_list_of_template_databases \ "SELECT pg_catalog.quote_ident(d.datname) "\ " FROM pg_catalog.pg_database d "\ @@ -1872,11 +1917,10 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH_LIST2("ATTRIBUTE", "VALUE"); /* ALTER TYPE RENAME */ else if (Matches4("ALTER", "TYPE", MatchAny, "RENAME")) - COMPLETE_WITH_LIST2("ATTRIBUTE", "TO"); - /* ALTER TYPE xxx RENAME ATTRIBUTE yyy */ - else if (Matches6("ALTER", "TYPE", MatchAny, "RENAME", "ATTRIBUTE", MatchAny)) + COMPLETE_WITH_LIST3("ATTRIBUTE", "TO", "VALUE"); + /* ALTER TYPE xxx RENAME (ATTRIBUTE|VALUE) yyy */ + else if (Matches6("ALTER", "TYPE", MatchAny, "RENAME", "ATTRIBUTE|VALUE", MatchAny)) COMPLETE_WITH_CONST("TO"); - /* * If we have ALTER TYPE ALTER/DROP/RENAME ATTRIBUTE, provide list * of attributes @@ -1896,6 +1940,12 @@ psql_completion(const char *text, int start, int end) else if (Matches5("ALTER", "GROUP", MatchAny, "ADD|DROP", "USER")) COMPLETE_WITH_QUERY(Query_for_list_of_roles); + /* + * If we have ALTER TYPE RENAME VALUE, provide list of enum values + */ + else if (Matches5("ALTER", "TYPE", MatchAny, "RENAME", "VALUE")) + COMPLETE_WITH_ENUM_VALUE(prev3_wd); + /* BEGIN */ else if (Matches1("BEGIN")) COMPLETE_WITH_LIST6("WORK", "TRANSACTION", "ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE"); -- 2.10.2 --=-=-= -- - Twitter seems more influential [than blogs] in the 'gets reported in the mainstream press' sense at least. - Matt McLeod - That'd be because the content of a tweet is easier to condense down to a mainstream media article. - Calle Dybedahl --=-=-= Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --=-=-=--