From: ilmari@ilmari.org
To: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [PATCH] Improve tab completion for CREATE TABLE
Date: Thu, 20 Dec 2018 00:02:52 +0000
Message-ID: <d8j8t0lf4k3.fsf@dalvik.ping.uio.no> (raw)
In-Reply-To: <20181219234408.GD27104@paquier.xyz>
References: <d8j1s77kdbb.fsf@dalvik.ping.uio.no>
<d8j7eguin89.fsf@dalvik.ping.uio.no>
<20181219050530.GC19856@paquier.xyz>
<d8jh8f9f6fe.fsf@dalvik.ping.uio.no>
<20181219234408.GD27104@paquier.xyz>
Michael Paquier <michael@paquier.xyz> writes:
> On Wed, Dec 19, 2018 at 11:22:29PM +0000, Dagfinn Ilmari Mannsåker wrote:
>> Michael Paquier <michael@paquier.xyz> writes:
>>> + /* Complete ON COMMIT actions for temp tables */
>>> + else if (TailMatches("ON", "COMMIT"))
>>> + COMPLETE_WITH("PRESERVE ROWS", "DELETE ROWS", "DROP");
>>>
>>> This causes ON COMMIT to show up for permanent and unlogged tables.
>>
>> No, this is for completing _after_ ON COMMIT, which is only suggested by
>> the clause for temporary tables above.
>
> If a user types "CREATE TABLE foo () ON COMMIT" by himself and then asks
> for tab completion then he would get the suggestion, which is incorrect?
Point, fixed in the attached v4. OTOH, as I mentioned in my other
email, that runs into the problem that it won't complete the actions
after e.g. "CREATE TEMP TABLE FOO () WITH () ON COMMIT".
--
- 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
Attachments:v4-0001-Tab-complete-more-options-for-CREATE-TABLE.patch (text/x-diff, 2.9K) download
From 294480116f52ba96ad10ed49850ffc3785e1a43c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Fri, 23 Nov 2018 15:23:21 +0000
Subject: [PATCH v4] Tab complete more options for CREATE TABLE
- ( or OF or PARTITION OF after the name- composite type names after CREATE TABLE <name> 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.cindex fa44b2820b..2996c8e68f 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 <name> */+ 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 <name> 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("CREATE", "TEMP|TEMPORARY", "TABLE", MatchAny, "(*)", "ON", "COMMIT"))+ COMPLETE_WITH("PRESERVE ROWS", "DELETE ROWS", "DROP");
/* CREATE TABLESPACE */
else if (Matches("CREATE", "TABLESPACE", MatchAny))
--
2.20.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: ilmari@ilmari.org, michael@paquier.xyz
Subject: Re: [PATCH] Improve tab completion for CREATE TABLE
In-Reply-To: <d8j8t0lf4k3.fsf@dalvik.ping.uio.no>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox