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 1gZlRe-0000Kf-5s for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Dec 2018 23:40:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZlRc-0000yV-U0 for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Dec 2018 23:40:04 +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 1gZlRc-0000wq-Li for pgsql-hackers@lists.postgresql.org; Wed, 19 Dec 2018 23:40:04 +0000 Received: from ping.uio.no ([2001:700:100:570::196]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZlRa-0008Av-7M for pgsql-hackers@postgresql.org; Wed, 19 Dec 2018 23:40:04 +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 1gZlRX-0003eA-MY; Thu, 20 Dec 2018 00:40:01 +0100 Received: from ilmari by dalvik.ping.uio.no with local (Exim 4.84_2) (envelope-from ) id 1gZlRX-0002GB-HW; Thu, 20 Dec 2018 00:39:59 +0100 From: ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) To: Michael Paquier Cc: pgsql-hackers@postgresql.org Subject: Re: [PATCH] Improve tab completion for CREATE TABLE References: <20181219050530.GC19856@paquier.xyz> Mail-Copies-To: nobody Date: Wed, 19 Dec 2018 23:39:59 +0000 In-Reply-To: ("Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker=22's?= message of "Wed, 19 Dec 2018 23:22:29 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (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 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes: > Michael Paquier writes: > >> On Fri, Nov 30, 2018 at 03:44:38PM +0000, Dagfinn Ilmari Mannsåker wrote: >>> ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes: >>>> Please find attached a patch that adds the following tab completions for >>>> CREATE TABLE: >>> >>> Added to the 2019-01 commitfest: https://commitfest.postgresql.org/21/1895/ >> >> + else if (TailMatches("CREATE", "TABLE", MatchAny) || >> + TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny)) >> + COMPLETE_WITH("(", "PARTITION OF"); >> >> This is missing the completion of "OF TYPE" (no need to print the type >> matches). > > Good catch. I've added that, and separate completion of composite type > names after it in the attached v2 patch. Oops, that had a typo after I fiddled with the formatting of the selcondition in the query and forgot to compile check it. Fixed v3 patch attached. Another omission I just realised of is that it doesn't complete the list of table storage options after after "WITH (". That should be fairly easy to add (we already have the list for completing after ALTER TABLE SET|RESET), but it's getting late here now. Also, when there are multiple things that can all appear in any order in a given place in the grammar, it completes them all there, but it doesn't complete the rest after you've typed one one. E.g. it won't complete WITH or any of the other options after CREATE TABLE ( ... ) TABLESPACE . This seems like a more involved change, and probably a more widespread problem, so I'm tempted to leave that for another patch. - ilmari -- "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v3-0001-Tab-complete-more-options-for-CREATE-TABLE.patch From 3aff843fb5c5c608b33a8c9bf6008134c9b75ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Fri, 23 Nov 2018 15:23:21 +0000 Subject: [PATCH v3] Tab complete more options for CREATE TABLE - ( or OF or PARTITION OF after the name - composite type names after CREATE TABLE OF - options after the column list - actions after ON COMMIT --- src/bin/psql/tab-complete.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index fa44b2820b..e7a618b3e3 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -344,6 +344,18 @@ static const SchemaQuery Query_for_list_of_datatypes = { .qualresult = "pg_catalog.quote_ident(t.typname)", }; +static const SchemaQuery Query_for_list_of_composite_datatypes = { + .catname = "pg_catalog.pg_type t", + /* selcondition --- only get free-standing composite types */ + .selcondition = "(SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE) + " FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid) " + "AND t.typname !~ '^_'" + .viscondition = "pg_catalog.pg_type_is_visible(t.oid)", + .namespace = "t.typnamespace", + .result = "pg_catalog.format_type(t.oid, NULL)", + .qualresult = "pg_catalog.quote_ident(t.typname)", +}; + static const SchemaQuery Query_for_list_of_domains = { .catname = "pg_catalog.pg_type t", .selcondition = "t.typtype = 'd'", @@ -2412,6 +2424,23 @@ psql_completion(const char *text, int start, int end) /* Limited completion support for partition bound specification */ else if (TailMatches("PARTITION", "OF", MatchAny)) COMPLETE_WITH("FOR VALUES", "DEFAULT"); + /* Complete after CREATE TABLE */ + else if (TailMatches("CREATE", "TABLE", MatchAny) || + TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny)) + COMPLETE_WITH("(", "OF", "PARTITION OF"); + /* Complete with list of composite types after CREATE TABLE OF */ + else if (TailMatches("CREATE", "TABLE", MatchAny, "OF") || + TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "OF")) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes, NULL); + /* Complete options after CREATE TABLE name (...) */ + else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)") || + TailMatches("CREATE", "UNLOGGED", "TABLE", MatchAny, "(*)")) + COMPLETE_WITH("INHERITS (", "PARTITION BY", "WITH (", "TABLESPACE"); + else if (TailMatches("CREATE", "TEMP|TEMPORARY", "TABLE", MatchAny, "(*)")) + COMPLETE_WITH("INHERITS (", "PARTITION BY", "WITH (", "ON COMMIT", "TABLESPACE"); + /* Complete ON COMMIT actions for temp tables */ + else if (TailMatches("ON", "COMMIT")) + COMPLETE_WITH("PRESERVE ROWS", "DELETE ROWS", "DROP"); /* CREATE TABLESPACE */ else if (Matches("CREATE", "TABLESPACE", MatchAny)) -- 2.20.1 --=-=-=--