[PATCH]Add tab completion for foreigh table

Started by tanghy.fnst@fujitsu.comabout 4 years ago3 messages
#1tanghy.fnst@fujitsu.com
tanghy.fnst@fujitsu.com
1 attachment(s)

Hi

Attached a patch to improve the tab completion for foreigh table.

Also modified some DOC description of ALTER TABLE at [1]https://www.postgresql.org/docs/devel/sql-altertable.html in according with CREATE INDEX at [2]https://www.postgresql.org/docs/devel/sql-createindex.html.

In [1]https://www.postgresql.org/docs/devel/sql-altertable.html, we use "ALTER INDEX ATTACH PARTITION"
In [2]https://www.postgresql.org/docs/devel/sql-createindex.html, we use "ALTER INDEX ... ATTACH PARTITION"

I think the format in [2]https://www.postgresql.org/docs/devel/sql-createindex.html is better.

[1]: https://www.postgresql.org/docs/devel/sql-altertable.html
[2]: https://www.postgresql.org/docs/devel/sql-createindex.html

Regards,
Tang

Attachments:

v1-0001-add-tab-completion-for-PARTITION-OF-when-creating.patchapplication/octet-stream; name=v1-0001-add-tab-completion-for-PARTITION-OF-when-creating.patchDownload
From 8f976659b98202c30e90c701698cd54957794e3f Mon Sep 17 00:00:00 2001
From: tanghy <tanghy.fnst@fujitsu.com>
Date: Tue, 11 Jan 2022 17:28:15 +0900
Subject: [PATCH v1] add tab completion for PARTITION OF when creating foreign
 table


diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index a76e2e7322..93031968c8 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -723,7 +723,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       separately with additional <literal>SET TABLESPACE</literal> commands.
       When applied to a partitioned table, nothing is moved, but any
       partitions created afterwards with
-      <command>CREATE TABLE PARTITION OF</command> will use that tablespace,
+      <command>CREATE TABLE ... PARTITION OF</command> will use that tablespace,
       unless overridden by a <literal>TABLESPACE</literal> clause.
      </para>
 
@@ -956,7 +956,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       For each index in the target table, a corresponding
       one will be created in the attached table; or, if an equivalent
       index already exists, it will be attached to the target table's index,
-      as if <command>ALTER INDEX ATTACH PARTITION</command> had been executed.
+      as if <command>ALTER INDEX ... ATTACH PARTITION</command> had been executed.
       Note that if the existing table is a foreign table, it is currently not
       allowed to attach the table as a partition of the target table if there
       are <literal>UNIQUE</literal> indexes on the target table.  (See also
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 39be6f556a..46f05b90cf 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2636,6 +2636,10 @@ psql_completion(const char *text, int start, int end)
 	else if (Matches("CREATE", "FOREIGN", "DATA", "WRAPPER", MatchAny))
 		COMPLETE_WITH("HANDLER", "VALIDATOR", "OPTIONS");
 
+	/* CREATE FOREIGN TABLE*/
+	else if (Matches("CREATE", "FOREIGN", "TABLE", MatchAny))
+		COMPLETE_WITH("PARTITION OF");
+
 	/* CREATE INDEX --- is allowed inside CREATE SCHEMA, so use TailMatches */
 	/* First off we complete CREATE UNIQUE with "INDEX" */
 	else if (TailMatches("CREATE", "UNIQUE"))
-- 
2.33.0.windows.2

#2Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: tanghy.fnst@fujitsu.com (#1)
Re: [PATCH]Add tab completion for foreigh table

On 2022/01/11 21:43, tanghy.fnst@fujitsu.com wrote:

Hi

Attached a patch to improve the tab completion for foreigh table.

Thanks!

Isn't it better to tab-complete not only "PARTITION OF" but also "(" for CREATE FOREIGN TABLE?

Also modified some DOC description of ALTER TABLE at [1] in according with CREATE INDEX at [2].

In [1], we use "ALTER INDEX ATTACH PARTITION"
In [2], we use "ALTER INDEX ... ATTACH PARTITION"

I think the format in [2] is better.

Agreed.

IMO it's better to make the docs changes in separate patch because they are not directly related to the improvement of tab-completion.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#3tanghy.fnst@fujitsu.com
tanghy.fnst@fujitsu.com
In reply to: Fujii Masao (#2)
2 attachment(s)
RE: [PATCH]Add tab completion for foreigh table

On Thursday, January 13, 2022 12:38 PM, Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

Isn't it better to tab-complete not only "PARTITION OF" but also "(" for CREATE
FOREIGN TABLE?

Thanks for your review. Left bracket completion added.

IMO it's better to make the docs changes in separate patch because they are not
directly related to the improvement of tab-completion.

Agreed. The former one patch was divided into two.
0001 patch, added tab completion for foreign table.
0002 patch, modified some doc description.

Regards,
Tang

Attachments:

v-0001-add-tab-completion-for-PARTITION-OF-when-creating.patchapplication/octet-stream; name=v-0001-add-tab-completion-for-PARTITION-OF-when-creating.patchDownload
From 0bf7f83272c7bd3cb2e0e940cd572318aa5741b5 Mon Sep 17 00:00:00 2001
From: tanghy <tanghy.fnst@fujitsu.com>
Date: Tue, 11 Jan 2022 17:28:15 +0900
Subject: [PATCH v2] add tab completion for PARTITION OF when creating foreign
 table


diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index a76e2e7322..93031968c8 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -723,7 +723,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       separately with additional <literal>SET TABLESPACE</literal> commands.
       When applied to a partitioned table, nothing is moved, but any
       partitions created afterwards with
-      <command>CREATE TABLE PARTITION OF</command> will use that tablespace,
+      <command>CREATE TABLE ... PARTITION OF</command> will use that tablespace,
       unless overridden by a <literal>TABLESPACE</literal> clause.
      </para>
 
@@ -956,7 +956,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       For each index in the target table, a corresponding
       one will be created in the attached table; or, if an equivalent
       index already exists, it will be attached to the target table's index,
-      as if <command>ALTER INDEX ATTACH PARTITION</command> had been executed.
+      as if <command>ALTER INDEX ... ATTACH PARTITION</command> had been executed.
       Note that if the existing table is a foreign table, it is currently not
       allowed to attach the table as a partition of the target table if there
       are <literal>UNIQUE</literal> indexes on the target table.  (See also
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 39be6f556a..dab89ad46c 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2636,6 +2636,10 @@ psql_completion(const char *text, int start, int end)
 	else if (Matches("CREATE", "FOREIGN", "DATA", "WRAPPER", MatchAny))
 		COMPLETE_WITH("HANDLER", "VALIDATOR", "OPTIONS");
 
+	/* CREATE FOREIGN TABLE*/
+	else if (Matches("CREATE", "FOREIGN", "TABLE", MatchAny))
+		COMPLETE_WITH("(", "PARTITION OF");
+
 	/* CREATE INDEX --- is allowed inside CREATE SCHEMA, so use TailMatches */
 	/* First off we complete CREATE UNIQUE with "INDEX" */
 	else if (TailMatches("CREATE", "UNIQUE"))
-- 
2.33.0.windows.2

v2-0002-Modify-doc-description-for-ALTER-TABLE-in-accordi.patchapplication/octet-stream; name=v2-0002-Modify-doc-description-for-ALTER-TABLE-in-accordi.patchDownload
From b3bdaa71963dd0df332fa2dc82a034a2a904cb61 Mon Sep 17 00:00:00 2001
From: tanghy <tanghy.fnst@fujitsu.com>
Date: Thu, 13 Jan 2022 14:54:59 +0900
Subject: [PATCH v2 2/2] Modify doc description for ALTER TABLE in according
 with CREATE INDEX


diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index a76e2e7322..93031968c8 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -723,7 +723,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       separately with additional <literal>SET TABLESPACE</literal> commands.
       When applied to a partitioned table, nothing is moved, but any
       partitions created afterwards with
-      <command>CREATE TABLE PARTITION OF</command> will use that tablespace,
+      <command>CREATE TABLE ... PARTITION OF</command> will use that tablespace,
       unless overridden by a <literal>TABLESPACE</literal> clause.
      </para>
 
@@ -956,7 +956,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       For each index in the target table, a corresponding
       one will be created in the attached table; or, if an equivalent
       index already exists, it will be attached to the target table's index,
-      as if <command>ALTER INDEX ATTACH PARTITION</command> had been executed.
+      as if <command>ALTER INDEX ... ATTACH PARTITION</command> had been executed.
       Note that if the existing table is a foreign table, it is currently not
       allowed to attach the table as a partition of the target table if there
       are <literal>UNIQUE</literal> indexes on the target table.  (See also
-- 
2.33.0.windows.2