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

