public inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH 1/5] bootstrap: convert Typ to a List*
11+ messages / 4 participants
[nested] [flat]

* [PATCH 1/5] bootstrap: convert Typ to a List*
@ 2020-11-20 02:48  Justin Pryzby <[email protected]>
  0 siblings, 0 replies; 11+ messages in thread

From: Justin Pryzby @ 2020-11-20 02:48 UTC (permalink / raw)

---
 src/backend/bootstrap/bootstrap.c | 69 ++++++++++++++-----------------
 1 file changed, 31 insertions(+), 38 deletions(-)

diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 6f615e6622..18eb62ca47 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -159,7 +159,7 @@ struct typmap
 	FormData_pg_type am_typ;
 };
 
-static struct typmap **Typ = NULL;
+static List *Typ = NIL; /* List of struct typmap* */
 static struct typmap *Ap = NULL;
 
 static Datum values[MAXATTR];	/* current row's attribute values */
@@ -597,7 +597,7 @@ boot_openrel(char *relname)
 	 * pg_type must be filled before any OPEN command is executed, hence we
 	 * can now populate the Typ array if we haven't yet.
 	 */
-	if (Typ == NULL)
+	if (Typ == NIL)
 		populate_typ_array();
 
 	if (boot_reldesc != NULL)
@@ -688,7 +688,7 @@ DefineAttr(char *name, char *type, int attnum, int nullness)
 
 	typeoid = gettype(type);
 
-	if (Typ != NULL)
+	if (Typ != NIL)
 	{
 		attrtypes[attnum]->atttypid = Ap->am_oid;
 		attrtypes[attnum]->attlen = Ap->am_typ.typlen;
@@ -877,36 +877,25 @@ populate_typ_array(void)
 	Relation	rel;
 	TableScanDesc scan;
 	HeapTuple	tup;
-	int			nalloc;
-	int			i;
-
-	Assert(Typ == NULL);
 
-	nalloc = 512;
-	Typ = (struct typmap **)
-		MemoryContextAlloc(TopMemoryContext, nalloc * sizeof(struct typmap *));
+	Assert(Typ == NIL);
 
 	rel = table_open(TypeRelationId, NoLock);
 	scan = table_beginscan_catalog(rel, 0, NULL);
-	i = 0;
 	while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
 	{
 		Form_pg_type typForm = (Form_pg_type) GETSTRUCT(tup);
+		struct typmap *newtyp;
+		MemoryContext old;
 
-		/* make sure there will be room for a trailing NULL pointer */
-		if (i >= nalloc - 1)
-		{
-			nalloc *= 2;
-			Typ = (struct typmap **)
-				repalloc(Typ, nalloc * sizeof(struct typmap *));
-		}
-		Typ[i] = (struct typmap *)
-			MemoryContextAlloc(TopMemoryContext, sizeof(struct typmap));
-		Typ[i]->am_oid = typForm->oid;
-		memcpy(&(Typ[i]->am_typ), typForm, sizeof(Typ[i]->am_typ));
-		i++;
+		old = MemoryContextSwitchTo(TopMemoryContext);
+		newtyp = (struct typmap *) palloc(sizeof(struct typmap));
+		Typ = lappend(Typ, newtyp);
+		MemoryContextSwitchTo(old);
+
+		newtyp->am_oid = typForm->oid;
+		memcpy(&newtyp->am_typ, typForm, sizeof(newtyp->am_typ));
 	}
-	Typ[i] = NULL;				/* Fill trailing NULL pointer */
 	table_endscan(scan);
 	table_close(rel, NoLock);
 }
@@ -925,16 +914,17 @@ populate_typ_array(void)
 static Oid
 gettype(char *type)
 {
-	if (Typ != NULL)
+	if (Typ != NIL)
 	{
-		struct typmap **app;
+		ListCell *lc;
 
-		for (app = Typ; *app != NULL; app++)
+		foreach (lc, Typ)
 		{
-			if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
+			struct typmap *app = lfirst(lc);
+			if (strncmp(NameStr(app->am_typ.typname), type, NAMEDATALEN) == 0)
 			{
-				Ap = *app;
-				return (*app)->am_oid;
+				Ap = app;
+				return app->am_oid;
 			}
 		}
 	}
@@ -980,14 +970,17 @@ boot_get_type_io_data(Oid typid,
 	if (Typ != NULL)
 	{
 		/* We have the boot-time contents of pg_type, so use it */
-		struct typmap **app;
-		struct typmap *ap;
-
-		app = Typ;
-		while (*app && (*app)->am_oid != typid)
-			++app;
-		ap = *app;
-		if (ap == NULL)
+		struct typmap *ap = NULL;
+		ListCell *lc;
+
+		foreach (lc, Typ)
+		{
+			ap = lfirst(lc);
+			if (ap->am_oid == typid)
+				break;
+		}
+
+		if (!ap || ap->am_oid != typid)
 			elog(ERROR, "type OID %u not found in Typ list", typid);
 
 		*typlen = ap->am_typ.typlen;
-- 
2.26.2


--------------614DDB87AFFED893713AC0E9
Content-Type: text/x-patch; charset=UTF-8;
 name="0002-Allow-composite-types-in-bootstrap-20210304.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0002-Allow-composite-types-in-bootstrap-20210304.patch"



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* DOC: fixes multiple errors in alter table doc
@ 2025-12-18 07:22  Chao Li <[email protected]>
  0 siblings, 2 replies; 11+ messages in thread

From: Chao Li @ 2025-12-18 07:22 UTC (permalink / raw)
  To: Postgres hackers <[email protected]>

Hi Hacker,

While working on a patch these days, my eyes are on the “alter table” doc,
and found multiple errors:

1. Several sub-commands are missed in the top “action” list:

   * ALTER COLUMN SET <sequence-option>
   * ALTER COLUMN RESTART
   * RENAME
   * SET SCHEMA
   * ATTACH PARTITION
   * DETACH PARTITION
   * MERGE PARTITION
   * SPLIT PARTITION

2. In sub-command details section, "ADD COLUMN [ IF NOT EXISTS ]” missed
“[]" with “COLUMN”, which is misleading, because “COLUMN” is actually
optional.

3. For all “alter column” sub-commands, "ALTER [ COLUMN ]” are omitted,
which is also confusing, because none of other sub-commands omit their
prefix part.

This patch fixed all these issue.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/


Attachments:

  [application/octet-stream] v1-0001-doc-clarify-and-complete-ALTER-TABLE-syntax-in-re.patch (10.9K, ../../CAEoWx2n6ShLMOnjOtf63TjjgGbgiTVT5OMsSOFmbjGb6Xue1Bw@mail.gmail.com/3-v1-0001-doc-clarify-and-complete-ALTER-TABLE-syntax-in-re.patch)
  download | inline diff:
From ac2dea06882535671165e38aaa384171396fbe88 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <[email protected]>
Date: Thu, 18 Dec 2025 15:18:22 +0800
Subject: [PATCH v1] doc: clarify and complete ALTER TABLE syntax in reference
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The ALTER TABLE syntax synopsis and command descriptions were incomplete
and inconsistent with the actual grammar.

Update the syntax summary to list missing ALTER TABLE variants, including
column-level sequence operations, rename actions, schema changes, and
partition management commands. Adjust individual command descriptions
to consistently show the full ALTER [ COLUMN ] column_name … forms,
matching the grammar and improving readability.

This is a documentation-only change; no behavior is altered.

Author: Chao Li <[email protected]>
---
 doc/src/sgml/ref/alter_table.sgml | 41 ++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 9abd8037f28..c329cb201de 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -57,6 +57,8 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
     ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> ADD GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( <replaceable>sequence_options</replaceable> ) ]
     ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> { SET GENERATED { ALWAYS | BY DEFAULT } | SET <replaceable>sequence_option</replaceable> | RESTART [ [ WITH ] <replaceable class="parameter">restart</replaceable> ] } [...]
     ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> DROP IDENTITY [ IF EXISTS ]
+    ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET <replaceable>sequence_option</replaceable>
+    ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> RESTART
     ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET STATISTICS { <replaceable class="parameter">integer</replaceable> | DEFAULT }
     ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET ( <replaceable class="parameter">attribute_option</replaceable> = <replaceable class="parameter">value</replaceable> [, ... ] )
     ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> RESET ( <replaceable class="parameter">attribute_option</replaceable> [, ... ] )
@@ -94,6 +96,15 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
     NOT OF
     OWNER TO { <replaceable class="parameter">new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
     REPLICA IDENTITY { DEFAULT | USING INDEX <replaceable class="parameter">index_name</replaceable> | FULL | NOTHING }
+    RENAME TO <replaceable class="parameter">new_table_name</replaceable>
+    RENAME COLUMN <replaceable class="parameter">old_column_name</replaceable> TO <replaceable class="parameter">new_column_name</replaceable>
+    RENAME CONSTRAINT <replaceable class="parameter">old_constraint_name</replaceable> TO <replaceable class="parameter">new_constraint_name</replaceable>
+    RENAME INDEX <replaceable class="parameter">old_index_name</replaceable> TO <replaceable class="parameter">new_index_name</replaceable>
+    SET SCHEMA <replaceable class="parameter">new_schema_name</replaceable>
+    ATTACH PARTITION <replaceable class="parameter">partition_name</replaceable> { FOR VALUES <replaceable>partition_bound_spec</replaceable> | DEFAULT }
+    DETACH PARTITION <replaceable class="parameter">partition_name</replaceable> [ CONCURRENTLY | FINALIZE ]
+    MERGE PARTITIONS (<replaceable class="parameter">partition_name1</replaceable>, <replaceable class="parameter">partition_name2</replaceable> [, ...]) INTO <replaceable class="parameter">partition_name</replaceable>
+    SPLIT PARTITION <replaceable class="parameter">partition_name</replaceable> INTO ( PARTITION <replaceable class="parameter">partition_name1</replaceable> { FOR VALUES <replaceable>partition_bound_spec</replaceable> | DEFAULT }, PARTITION <replaceable class="parameter">partition_name2</replaceable> { FOR VALUES <replaceable>partition_bound_spec</replaceable> | DEFAULT } [, ...])
 
 <phrase>and <replaceable class="parameter">partition_bound_spec</replaceable> is:</phrase>
 
@@ -163,7 +174,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
 
   <variablelist>
    <varlistentry id="sql-altertable-desc-add-column">
-    <term><literal>ADD COLUMN [ IF NOT EXISTS ]</literal></term>
+    <term><literal>ADD [ COLUMN ] [ IF NOT EXISTS ]</literal></term>
     <listitem>
      <para>
       This form adds a new column to the table, using the same syntax as
@@ -175,7 +186,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-drop-column">
-    <term><literal>DROP COLUMN [ IF EXISTS ]</literal></term>
+    <term><literal>DROP [ COLUMN ] [ IF EXISTS ]</literal></term>
     <listitem>
      <para>
       This form drops a column from a table.  Indexes and
@@ -194,7 +205,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-set-data-type">
-    <term><literal>SET DATA TYPE</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> [ SET DATA ] TYPE</literal></term>
     <listitem>
      <para>
       This form changes the type of a column of a table. Indexes and
@@ -223,7 +234,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-set-drop-default">
-    <term><literal>SET</literal>/<literal>DROP DEFAULT</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> { SET | DROP } DEFAULT</literal></term>
     <listitem>
      <para>
       These forms set or remove the default value for a column (where
@@ -236,7 +247,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-set-drop-not-null">
-    <term><literal>SET</literal>/<literal>DROP NOT NULL</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> { SET | DROP } NOT NULL</literal></term>
     <listitem>
      <para>
       These forms change whether a column is marked to allow null
@@ -272,7 +283,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-set-expression">
-    <term><literal>SET EXPRESSION AS</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET EXPRESSION AS</literal></term>
     <listitem>
      <para>
       This form replaces the expression of a generated column.  Existing data
@@ -292,7 +303,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-drop-expression">
-    <term><literal>DROP EXPRESSION [ IF EXISTS ]</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> DROP EXPRESSION [ IF EXISTS ]</literal></term>
     <listitem>
      <para>
       This form turns a stored generated column into a normal base column.
@@ -314,9 +325,9 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-generated-identity">
-    <term><literal>ADD GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY</literal></term>
-    <term><literal>SET GENERATED { ALWAYS | BY DEFAULT }</literal></term>
-    <term><literal>DROP IDENTITY [ IF EXISTS ]</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> ADD GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET GENERATED { ALWAYS | BY DEFAULT }</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> DROP IDENTITY [ IF EXISTS ]</literal></term>
     <listitem>
      <para>
       These forms change whether a column is an identity column or change the
@@ -350,7 +361,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-set-statistics">
-    <term><literal>SET STATISTICS</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET STATISTICS</literal></term>
     <listitem>
      <para>
       This form
@@ -373,8 +384,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-set-attribute-option">
-    <term><literal>SET ( <replaceable class="parameter">attribute_option</replaceable> = <replaceable class="parameter">value</replaceable> [, ... ] )</literal></term>
-    <term><literal>RESET ( <replaceable class="parameter">attribute_option</replaceable> [, ... ] )</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET ( <replaceable class="parameter">attribute_option</replaceable> = <replaceable class="parameter">value</replaceable> [, ... ] )</literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> RESET ( <replaceable class="parameter">attribute_option</replaceable> [, ... ] )</literal></term>
     <listitem>
      <para>
       This form sets or resets per-attribute options.  Currently, the only
@@ -408,7 +419,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
 
    <varlistentry id="sql-altertable-desc-set-storage">
     <term>
-     <literal>SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT }</literal>
+     <literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT }</literal>
      <indexterm>
       <primary>TOAST</primary>
       <secondary>per-column storage settings</secondary>
@@ -442,7 +453,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
 
    <varlistentry id="sql-altertable-desc-set-compression">
     <term>
-     <literal>SET COMPRESSION <replaceable class="parameter">compression_method</replaceable></literal>
+     <literal>ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET COMPRESSION <replaceable class="parameter">compression_method</replaceable></literal>
     </term>
     <listitem>
      <para>
-- 
2.39.5 (Apple Git-154)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: DOC: fixes multiple errors in alter table doc
@ 2025-12-19 05:26  Chao Li <[email protected]>
  parent: Chao Li <[email protected]>
  1 sibling, 0 replies; 11+ messages in thread

From: Chao Li @ 2025-12-19 05:26 UTC (permalink / raw)
  To: Postgres hackers <[email protected]>



> On Dec 18, 2025, at 15:22, Chao Li <[email protected]> wrote:
> 
> Hi Hacker,
> 
> While working on a patch these days, my eyes are on the “alter table” doc, and found multiple errors:
> 
> 1. Several sub-commands are missed in the top “action” list:
> 
>    * ALTER COLUMN SET <sequence-option>
>    * ALTER COLUMN RESTART
>    * RENAME
>    * SET SCHEMA
>    * ATTACH PARTITION
>    * DETACH PARTITION
>    * MERGE PARTITION
>    * SPLIT PARTITION
> 
> 2. In sub-command details section, "ADD COLUMN [ IF NOT EXISTS ]” missed “[]" with “COLUMN”, which is misleading, because “COLUMN” is actually optional.
> 
> 3. For all “alter column” sub-commands, "ALTER [ COLUMN ]” are omitted, which is also confusing, because none of other sub-commands omit their prefix part.
> 
> This patch fixed all these issue.
> 
> <v1-0001-doc-clarify-and-complete-ALTER-TABLE-syntax-in-re.patch>

CF entry created: https://commitfest.postgresql.org/patch/6328/

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: DOC: fixes multiple errors in alter table doc
@ 2026-01-22 09:38  Chao Li <[email protected]>
  parent: Chao Li <[email protected]>
  1 sibling, 1 reply; 11+ messages in thread

From: Chao Li @ 2026-01-22 09:38 UTC (permalink / raw)
  To: Robert Treat <[email protected]>; +Cc: Postgres hackers <[email protected]>

On Thu, Jan 22, 2026 at 5:33 PM Chao Li <[email protected]> wrote:

>
>
> > On Jan 8, 2026, at 09:38, Chao Li <[email protected]> wrote:
> >
> >
> >
> >> On Jan 8, 2026, at 07:13, Robert Treat <[email protected]> wrote:
> >>
> >> On Sat, Jan 3, 2026 at 11:30 PM Chao Li <[email protected]> wrote:
> >>> On Jan 2, 2026, at 10:54, Robert Treat <[email protected]> wrote:
> >>> Hi Robert,
> >>>
> >>> Thanks you very much for your review.
> >>>
> >>>
> >>> On Thu, Dec 18, 2025 at 2:22 AM Chao Li <[email protected]>
> wrote:
> >>> Hi Hacker,
> >> <snip>
> >>> 2. In sub-command details section, "ADD COLUMN [ IF NOT EXISTS ]”
> missed “[]" with “COLUMN”, which is misleading, because “COLUMN” is
> actually optional.
> >>>
> >>> Seems technically correct and potentially useful, and I see you
> >>> handled this for the DROP COLUMN variant as well, so I could see a +1
> >>> on this one.
> >>>
> >>> Thanks for confirming.
> >>>
> >>>
> >>> 3. For all “alter column” sub-commands, "ALTER [ COLUMN ]” are
> omitted, which is also confusing, because none of other sub-commands omit
> their prefix part.
> >>>
> >>>
> >>> Hmm... I'm curious what you find confusing about this. Is the
> >>> confusion in trying to find or understand the information presented,
> >>> or confusing as to why it isn't all documented the same way? The
> >>> downside of your "fix" is that this introduces a lot of extra text
> >>> that is more or less noise, especially for folks trying to skim the
> >>> documents looking for very specific command references.  And while I
> >>> agree that we aren't 100% consistent on this within the ALTER TABLE
> >>> subcommands, we use this same mixed pattern of omission on other pages
> >>> (see ALTER TYPE for instance). If we were to insist on making this
> >>> consistent here, I think we'd probably need to look at other pages as
> >>> well and evaluate or update them too. I'm not sure that would be an
> >>> improvement though.
> >>>
> >>>
> >>> The confusion came from my own first-time reading of the
> documentation. Since the page is quite long, when I was reading the action
> descriptions and wanted to confirm the exact sub-command syntax, I often
> had to scroll back up to the syntax section. That led me to think it might
> be helpful to include the full sub-command form directly with the action
> descriptions.
> >>>
> >>> That said, I understand your concern. The change did make the text
> longer and added noise. In v2, I’ve therefore reverted that broader change.
> As you pointed out, if we were to pursue this kind of consistency, it would
> need to be handled across other similar pages as well, which would be
> better done as a dedicated and more carefully scoped patch.
> >>>
> >>> So, v2’s scope is significantly reduced, only a fix for my original
> point 2 is retained.
> >>>
> >>
> >> Makes sense to me and seems like an improvement, so +1.
> >>
> >
> > Hi Robert,
> >
> > Thank you very much for your review. This is the CF entry
> https://commitfest.postgresql.org/patch/6328/, you may add you as a
> reviewer. And I just changed the status to Ready for Committer.
> >
> > Best regards,
> > --
> > Chao Li (Evan)
> > HighGo Software Co., Ltd.
> > https://www.highgo.com/
>
> Bump. This is a tiny doc fix.
>

PFA v3: Rebased, and added reviewer and discussion information.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/


Attachments:

  [application/octet-stream] v3-0001-docs-reflect-optional-COLUMN-keyword-in-ALTER-TAB.patch (1.8K, ../../CAEoWx2mOW=JMjSNrNsc3b-+8w0wbT2f6FSsyudD_Q-0pe_fkfw@mail.gmail.com/3-v3-0001-docs-reflect-optional-COLUMN-keyword-in-ALTER-TAB.patch)
  download | inline diff:
From 6921432e9ae12910a0cd3892a72631b3a061d1ae Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <[email protected]>
Date: Thu, 18 Dec 2025 15:18:22 +0800
Subject: [PATCH v3] docs: reflect optional COLUMN keyword in ALTER TABLE
 descriptions

The ALTER TABLE description entries for ADD COLUMN and DROP COLUMN
omitted the fact that the COLUMN keyword is optional. Adjust the
command summaries to match the documented syntax by marking COLUMN
as optional.

This is a documentation-only change; no behavior is altered.

Author: Chao Li <[email protected]>
Reviewed-by: Robert Treat <[email protected]>
Discussion: https://postgr.es/m/CAEoWx2n6ShLMOnjOtf63TjjgGbgiTVT5OMsSOFmbjGb6Xue1Bw@mail.gmail.com
---
 doc/src/sgml/ref/alter_table.sgml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 1bd479c917a..d69e5de8451 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -163,7 +163,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
 
   <variablelist>
    <varlistentry id="sql-altertable-desc-add-column">
-    <term><literal>ADD COLUMN [ IF NOT EXISTS ]</literal></term>
+    <term><literal>ADD [ COLUMN ] [ IF NOT EXISTS ]</literal></term>
     <listitem>
      <para>
       This form adds a new column to the table, using the same syntax as
@@ -175,7 +175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-drop-column">
-    <term><literal>DROP COLUMN [ IF EXISTS ]</literal></term>
+    <term><literal>DROP [ COLUMN ] [ IF EXISTS ]</literal></term>
     <listitem>
      <para>
       This form drops a column from a table.  Indexes and
-- 
2.50.1 (Apple Git-155)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: DOC: fixes multiple errors in alter table doc
@ 2026-03-02 09:04  Fujii Masao <[email protected]>
  parent: Chao Li <[email protected]>
  0 siblings, 1 reply; 11+ messages in thread

From: Fujii Masao @ 2026-03-02 09:04 UTC (permalink / raw)
  To: Chao Li <[email protected]>; +Cc: Robert Treat <[email protected]>; Postgres hackers <[email protected]>

On Thu, Jan 22, 2026 at 6:38 PM Chao Li <[email protected]> wrote:
> PFA v3: Rebased, and added reviewer and discussion information.

LGTM.

Should we apply the same change to the ALTER FOREIGN TABLE docs as well?

While reviewing that section, I noticed that ADD COLUMN IF NOT EXISTS appears
to work for ALTER FOREIGN TABLE, but it isn't documented. I'm not sure why
it was left out, but perhaps we should document it and add a regression test in
a separate patch?

Regards,

-- 
Fujii Masao





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: DOC: fixes multiple errors in alter table doc
@ 2026-03-02 09:22  Chao Li <[email protected]>
  parent: Fujii Masao <[email protected]>
  0 siblings, 1 reply; 11+ messages in thread

From: Chao Li @ 2026-03-02 09:22 UTC (permalink / raw)
  To: Fujii Masao <[email protected]>; +Cc: Robert Treat <[email protected]>; Postgres hackers <[email protected]>



> On Mar 2, 2026, at 17:04, Fujii Masao <[email protected]> wrote:
> 
> On Thu, Jan 22, 2026 at 6:38 PM Chao Li <[email protected]> wrote:
>> PFA v3: Rebased, and added reviewer and discussion information.
> 
> LGTM.
> 
> Should we apply the same change to the ALTER FOREIGN TABLE docs as well?

Sure, I can make the change.

> 
> While reviewing that section, I noticed that ADD COLUMN IF NOT EXISTS appears
> to work for ALTER FOREIGN TABLE, but it isn't documented. I'm not sure why
> it was left out, but perhaps we should document it and add a regression test in
> a separate patch?
> 

I will verify that, then update the doc and regression test accordingly.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: DOC: fixes multiple errors in alter table doc
@ 2026-03-03 02:09  Chao Li <[email protected]>
  parent: Chao Li <[email protected]>
  0 siblings, 1 reply; 11+ messages in thread

From: Chao Li @ 2026-03-03 02:09 UTC (permalink / raw)
  To: Fujii Masao <[email protected]>; +Cc: Robert Treat <[email protected]>; Postgres hackers <[email protected]>



> On Mar 2, 2026, at 17:22, Chao Li <[email protected]> wrote:
> 
> 
> 
>> On Mar 2, 2026, at 17:04, Fujii Masao <[email protected]> wrote:
>> 
>> On Thu, Jan 22, 2026 at 6:38 PM Chao Li <[email protected]> wrote:
>>> PFA v3: Rebased, and added reviewer and discussion information.
>> 
>> LGTM.
>> 
>> Should we apply the same change to the ALTER FOREIGN TABLE docs as well?
> 
> Sure, I can make the change.
> 
>> 
>> While reviewing that section, I noticed that ADD COLUMN IF NOT EXISTS appears
>> to work for ALTER FOREIGN TABLE, but it isn't documented. I'm not sure why
>> it was left out, but perhaps we should document it and add a regression test in
>> a separate patch?
>> 
> 
> I will verify that, then update the doc and regression test accordingly.
> 
> Best regards,
> --
> Chao Li (Evan)
> HighGo Software Co., Ltd.
> https://www.highgo.com/
> 

PFA v4:

0001 - alter table related changes

 * Add test cases for omitting COLUMN of ALTER TABLE ADD/DROP [COLUMN]
 * Add a test case for ADD COLUMN IF NOT EXIST (already had DROP COLUMN IF EXIST)

0002 - alter foreign table related changes

 * doc: Add IF NOT EXSTS for ADD COLUMN
 * doc: Mark COLUMN as optional for ADD/DROP COLUMN in the same way as 0001
 * Add test cases for omitting COLUMN of ALTER FOREIGN TABLE ADD/DROP [COLUMN]
 * Add a test cases for for ADD COLUMN IF NOT EXIST
 * Add a test cases for for DROP COLUMN IF EXIST

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






Attachments:

  [application/octet-stream] v4-0001-doc-clarify-optional-COLUMN-in-ALTER-TABLE-ADD-DR.patch (3.6K, ../../[email protected]/2-v4-0001-doc-clarify-optional-COLUMN-in-ALTER-TABLE-ADD-DR.patch)
  download | inline diff:
From 5fa11495a4e7b10755a4017d8e1498435ae3e507 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <[email protected]>
Date: Tue, 3 Mar 2026 09:50:54 +0800
Subject: [PATCH v4 1/2] doc: clarify optional COLUMN in ALTER TABLE ADD/DROP

Adjust the ALTER TABLE reference page to reflect that the COLUMN keyword
is optional for ADD and DROP. The syntax was already accepted by the
parser, but the documentation only showed the COLUMN form.

Add regression tests covering:
- ALTER TABLE ADD without COLUMN
- ALTER TABLE ADD IF NOT EXISTS
- ALTER TABLE DROP without COLUMN

Author: Chao Li <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Reviewed-by: Robert Treat <[email protected]>
Discussion: https://postgr.es/m/CAEoWx2n6ShLMOnjOtf63TjjgGbgiTVT5OMsSOFmbjGb6Xue1Bw@mail.gmail.com
---
 doc/src/sgml/ref/alter_table.sgml         |  4 ++--
 src/test/regress/expected/alter_table.out | 10 ++++++++++
 src/test/regress/sql/alter_table.sql      |  8 ++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index aab2c6eb19f..00817e90360 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -163,7 +163,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
 
   <variablelist>
    <varlistentry id="sql-altertable-desc-add-column">
-    <term><literal>ADD COLUMN [ IF NOT EXISTS ]</literal></term>
+    <term><literal>ADD [ COLUMN ] [ IF NOT EXISTS ]</literal></term>
     <listitem>
      <para>
       This form adds a new column to the table, using the same syntax as
@@ -175,7 +175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
    </varlistentry>
 
    <varlistentry id="sql-altertable-desc-drop-column">
-    <term><literal>DROP COLUMN [ IF EXISTS ]</literal></term>
+    <term><literal>DROP [ COLUMN ] [ IF EXISTS ]</literal></term>
     <listitem>
      <para>
       This form drops a column from a table.  Indexes and
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index ac1a7345d0f..5998c670aa3 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -3849,6 +3849,16 @@ Referenced by:
 ALTER TABLE test_add_column
 	ADD COLUMN IF NOT EXISTS c5 SERIAL CHECK (c5 > 10);
 NOTICE:  column "c5" of relation "test_add_column" already exists, skipping
+ALTER TABLE test_add_column
+	ADD c6 integer; -- omit COLUMN
+ALTER TABLE test_add_column
+	ADD IF NOT EXISTS c6 integer;
+NOTICE:  column "c6" of relation "test_add_column" already exists, skipping
+ALTER TABLE test_add_column
+	DROP c6; -- omit COLUMN
+ALTER TABLE test_add_column
+	DROP IF EXISTS c6;
+NOTICE:  column "c6" of relation "test_add_column" does not exist, skipping
 \d test_add_column*
                             Table "public.test_add_column"
  Column |  Type   | Collation | Nullable |                   Default                   
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 417202430a5..d6b6381ae5c 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -2331,6 +2331,14 @@ ALTER TABLE test_add_column
 \d test_add_column
 ALTER TABLE test_add_column
 	ADD COLUMN IF NOT EXISTS c5 SERIAL CHECK (c5 > 10);
+ALTER TABLE test_add_column
+	ADD c6 integer; -- omit COLUMN
+ALTER TABLE test_add_column
+	ADD IF NOT EXISTS c6 integer;
+ALTER TABLE test_add_column
+	DROP c6; -- omit COLUMN
+ALTER TABLE test_add_column
+	DROP IF EXISTS c6;
 \d test_add_column*
 DROP TABLE test_add_column;
 \d test_add_column*
-- 
2.50.1 (Apple Git-155)



  [application/octet-stream] v4-0002-doc-clarify-ALTER-FOREIGN-TABLE-ADD-DROP-COLUMN-s.patch (8.0K, ../../[email protected]/3-v4-0002-doc-clarify-ALTER-FOREIGN-TABLE-ADD-DROP-COLUMN-s.patch)
  download | inline diff:
From d828ab6dfb764230098a7afaa349260b13125e4e Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <[email protected]>
Date: Tue, 3 Mar 2026 09:51:41 +0800
Subject: [PATCH v4 2/2] doc: clarify ALTER FOREIGN TABLE ADD/DROP COLUMN
 syntax

Update the ALTER FOREIGN TABLE reference page to reflect that:

- COLUMN is optional for ADD and DROP.
- IF NOT EXISTS is supported for ADD.

The syntax has long allowed these forms, but the documentation did not
fully reflect them.

Add regression tests for ALTER FOREIGN TABLE covering:
- ADD without COLUMN.
- ADD IF NOT EXISTS behavior.
- DROP without COLUMN.
- DROP IF EXISTS behavior.

Suggested-by: Fujii Masao <[email protected]>
Author: Chao Li <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/CAEoWx2n6ShLMOnjOtf63TjjgGbgiTVT5OMsSOFmbjGb6Xue1Bw@mail.gmail.com
---
 doc/src/sgml/ref/alter_foreign_table.sgml  | 8 +++++---
 src/test/regress/expected/foreign_data.out | 8 ++++++++
 src/test/regress/sql/foreign_data.sql      | 5 +++++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/doc/src/sgml/ref/alter_foreign_table.sgml b/doc/src/sgml/ref/alter_foreign_table.sgml
index e6d99e99016..228067f087c 100644
--- a/doc/src/sgml/ref/alter_foreign_table.sgml
+++ b/doc/src/sgml/ref/alter_foreign_table.sgml
@@ -32,7 +32,7 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceab
 
 <phrase>where <replaceable class="parameter">action</replaceable> is one of:</phrase>
 
-    ADD [ COLUMN ] <replaceable class="parameter">column_name</replaceable> <replaceable class="parameter">data_type</replaceable> [ COLLATE <replaceable class="parameter">collation</replaceable> ] [ <replaceable class="parameter">column_constraint</replaceable> [ ... ] ]
+    ADD [ COLUMN ] [ IF NOT EXISTS ] <replaceable class="parameter">column_name</replaceable> <replaceable class="parameter">data_type</replaceable> [ COLLATE <replaceable class="parameter">collation</replaceable> ] [ <replaceable class="parameter">column_constraint</replaceable> [ ... ] ]
     DROP [ COLUMN ] [ IF EXISTS ] <replaceable class="parameter">column_name</replaceable> [ RESTRICT | CASCADE ]
     ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> [ SET DATA ] TYPE <replaceable class="parameter">data_type</replaceable> [ COLLATE <replaceable class="parameter">collation</replaceable> ]
     ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET DEFAULT <replaceable class="parameter">expression</replaceable>
@@ -67,11 +67,13 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceab
 
   <variablelist>
    <varlistentry id="sql-alterforeigntable-desc-add-column">
-    <term><literal>ADD COLUMN</literal></term>
+    <term><literal>ADD [ COLUMN ] [ IF NOT EXISTS ]</literal></term>
     <listitem>
      <para>
       This form adds a new column to the foreign table, using the same syntax as
       <link linkend="sql-createforeigntable"><command>CREATE FOREIGN TABLE</command></link>.
+      If <literal>IF NOT EXISTS</literal> is specified and a column already
+      exists with this name, no error is thrown.
       Unlike the case when adding a column to a regular table, nothing happens
       to the underlying storage: this action simply declares that
       some new column is now accessible through the foreign table.
@@ -80,7 +82,7 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceab
    </varlistentry>
 
    <varlistentry id="sql-alterforeigntable-desc-drop-column">
-    <term><literal>DROP COLUMN [ IF EXISTS ]</literal></term>
+    <term><literal>DROP [ COLUMN ] [ IF EXISTS ]</literal></term>
     <listitem>
      <para>
       This form drops a column from a foreign table.
diff --git a/src/test/regress/expected/foreign_data.out b/src/test/regress/expected/foreign_data.out
index cce49e509ab..8bbf6a2d3dd 100644
--- a/src/test/regress/expected/foreign_data.out
+++ b/src/test/regress/expected/foreign_data.out
@@ -827,11 +827,15 @@ COMMENT ON COLUMN ft1.c1 IS 'foreign column';
 COMMENT ON COLUMN ft1.c1 IS NULL;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c4 integer;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c5 integer DEFAULT 0;
+ALTER FOREIGN TABLE ft1 ADD COLUMN IF NOT EXISTS c5 integer;
+NOTICE:  column "c5" of relation "ft1" already exists, skipping
 ALTER FOREIGN TABLE ft1 ADD COLUMN c6 integer;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c7 integer NOT NULL;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c8 integer;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c9 integer;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c10 integer OPTIONS (p1 'v1');
+ALTER FOREIGN TABLE ft1 ADD c12 integer; -- omit COLUMN
+ALTER FOREIGN TABLE ft1 DROP c12; -- omit COLUMN
 ALTER FOREIGN TABLE ft1 ALTER COLUMN c4 SET DEFAULT 0;
 ALTER FOREIGN TABLE ft1 ALTER COLUMN c5 DROP DEFAULT;
 ALTER FOREIGN TABLE ft1 ALTER COLUMN c6 SET NOT NULL;
@@ -929,6 +933,8 @@ FDW options: (quote '~', "be quoted" 'value', escape '@')
 -- alter noexisting table
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD COLUMN c4 integer;
 NOTICE:  relation "doesnt_exist_ft1" does not exist, skipping
+ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD c4 integer;
+NOTICE:  relation "doesnt_exist_ft1" does not exist, skipping
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD COLUMN c6 integer;
 NOTICE:  relation "doesnt_exist_ft1" does not exist, skipping
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD COLUMN c7 integer NOT NULL;
@@ -962,6 +968,8 @@ ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 OPTIONS (DROP delimiter, SET quot
 NOTICE:  relation "doesnt_exist_ft1" does not exist, skipping
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP COLUMN IF EXISTS no_column;
 NOTICE:  relation "doesnt_exist_ft1" does not exist, skipping
+ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP IF EXISTS no_column;
+NOTICE:  relation "doesnt_exist_ft1" does not exist, skipping
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP COLUMN c9;
 NOTICE:  relation "doesnt_exist_ft1" does not exist, skipping
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 SET SCHEMA foreign_schema;
diff --git a/src/test/regress/sql/foreign_data.sql b/src/test/regress/sql/foreign_data.sql
index aa147b14a90..00e71b73376 100644
--- a/src/test/regress/sql/foreign_data.sql
+++ b/src/test/regress/sql/foreign_data.sql
@@ -382,11 +382,14 @@ COMMENT ON COLUMN ft1.c1 IS NULL;
 
 ALTER FOREIGN TABLE ft1 ADD COLUMN c4 integer;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c5 integer DEFAULT 0;
+ALTER FOREIGN TABLE ft1 ADD COLUMN IF NOT EXISTS c5 integer;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c6 integer;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c7 integer NOT NULL;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c8 integer;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c9 integer;
 ALTER FOREIGN TABLE ft1 ADD COLUMN c10 integer OPTIONS (p1 'v1');
+ALTER FOREIGN TABLE ft1 ADD c12 integer; -- omit COLUMN
+ALTER FOREIGN TABLE ft1 DROP c12; -- omit COLUMN
 
 ALTER FOREIGN TABLE ft1 ALTER COLUMN c4 SET DEFAULT 0;
 ALTER FOREIGN TABLE ft1 ALTER COLUMN c5 DROP DEFAULT;
@@ -429,6 +432,7 @@ ALTER FOREIGN TABLE foreign_schema.ft1 RENAME TO foreign_table_1;
 
 -- alter noexisting table
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD COLUMN c4 integer;
+ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD c4 integer;
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD COLUMN c6 integer;
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD COLUMN c7 integer NOT NULL;
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD COLUMN c8 integer;
@@ -448,6 +452,7 @@ ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP CONSTRAINT ft1_c1_check;
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 OWNER TO regress_test_role;
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 OPTIONS (DROP delimiter, SET quote '~', ADD escape '@');
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP COLUMN IF EXISTS no_column;
+ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP IF EXISTS no_column;
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP COLUMN c9;
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 SET SCHEMA foreign_schema;
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 RENAME c1 TO foreign_column_1;
-- 
2.50.1 (Apple Git-155)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: DOC: fixes multiple errors in alter table doc
@ 2026-03-03 04:41  Robert Treat <[email protected]>
  parent: Chao Li <[email protected]>
  0 siblings, 1 reply; 11+ messages in thread

From: Robert Treat @ 2026-03-03 04:41 UTC (permalink / raw)
  To: Chao Li <[email protected]>; +Cc: Fujii Masao <[email protected]>; Postgres hackers <[email protected]>

On Mon, Mar 2, 2026 at 9:09 PM Chao Li <[email protected]> wrote:
> > On Mar 2, 2026, at 17:22, Chao Li <[email protected]> wrote:
> >> On Mar 2, 2026, at 17:04, Fujii Masao <[email protected]> wrote:
> >> On Thu, Jan 22, 2026 at 6:38 PM Chao Li <[email protected]> wrote:
> >>> PFA v3: Rebased, and added reviewer and discussion information.
> >>
> >> LGTM.
> >>
> >> Should we apply the same change to the ALTER FOREIGN TABLE docs as well?
> >
> > Sure, I can make the change.
> >
> >>
> >> While reviewing that section, I noticed that ADD COLUMN IF NOT EXISTS appears
> >> to work for ALTER FOREIGN TABLE, but it isn't documented. I'm not sure why
> >> it was left out, but perhaps we should document it and add a regression test in
> >> a separate patch?
> >>
> >
> > I will verify that, then update the doc and regression test accordingly.
> >
> > Best regards,
> > --
> > Chao Li (Evan)
> > HighGo Software Co., Ltd.
> > https://www.highgo.com/
> >
>
> PFA v4:
>
> 0001 - alter table related changes
>
>  * Add test cases for omitting COLUMN of ALTER TABLE ADD/DROP [COLUMN]
>  * Add a test case for ADD COLUMN IF NOT EXIST (already had DROP COLUMN IF EXIST)
>
> 0002 - alter foreign table related changes
>
>  * doc: Add IF NOT EXSTS for ADD COLUMN
>  * doc: Mark COLUMN as optional for ADD/DROP COLUMN in the same way as 0001
>  * Add test cases for omitting COLUMN of ALTER FOREIGN TABLE ADD/DROP [COLUMN]
>  * Add a test cases for for ADD COLUMN IF NOT EXIST
>  * Add a test cases for for DROP COLUMN IF EXIST
>

LGTM, although I was curious why you went with c12 vs c11 in
+ALTER FOREIGN TABLE ft1 ADD c12 integer; -- omit COLUMN
or maybe that should be changed?


Robert Treat
https://xzilla.net





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: DOC: fixes multiple errors in alter table doc
@ 2026-03-05 04:42  Fujii Masao <[email protected]>
  parent: Robert Treat <[email protected]>
  0 siblings, 1 reply; 11+ messages in thread

From: Fujii Masao @ 2026-03-05 04:42 UTC (permalink / raw)
  To: Chao Li <[email protected]>; +Cc: Robert Treat <[email protected]>; Postgres hackers <[email protected]>

On Tue, Mar 3, 2026 at 5:05 PM Chao Li <[email protected]> wrote:
> PFA v5:
>
> * In 0002, renamed c12 to c11 in the ALTER FOREIGN TABLE tests.
> * In 0002, added one more test case: ALTER FOREIGN TABLE ft1 DROP IF EXISTS no_column;

Thanks for updating the patches!

I've committed the 0001 patch and backpatched it to all supported versions.


 -- alter noexisting table
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD COLUMN c4 integer;
+ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD c5 integer;
<snip>
 ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP COLUMN IF EXISTS no_column;
+ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP IF EXISTS no_column;

Regarding 0002 patch, could you explain the reason for adding these
two additional tests? I was just curious why because other four tests that
the patch adds seem sufficient.

Aside from that point, the patch looks good to me.

Regards,

-- 
Fujii Masao





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: DOC: fixes multiple errors in alter table doc
@ 2026-03-06 06:40  Fujii Masao <[email protected]>
  parent: Fujii Masao <[email protected]>
  0 siblings, 1 reply; 11+ messages in thread

From: Fujii Masao @ 2026-03-06 06:40 UTC (permalink / raw)
  To: Chao Li <[email protected]>; +Cc: Robert Treat <[email protected]>; Postgres hackers <[email protected]>

On Thu, Mar 5, 2026 at 2:06 PM Chao Li <[email protected]> wrote:
> > -- alter noexisting table
> > ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD COLUMN c4 integer;
> > +ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 ADD c5 integer;
> > <snip>
> > ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP COLUMN IF EXISTS no_column;
> > +ALTER FOREIGN TABLE IF EXISTS doesnt_exist_ft1 DROP IF EXISTS no_column;
> >
> > Regarding 0002 patch, could you explain the reason for adding these
> > two additional tests? I was just curious why because other four tests that
> > the patch adds seem sufficient.
>
> They are combinations of “IF [NOT] EXISTS” and omitting “COLUMN", I added them just for better coverage.

Which table-level or column-level "IF [NOT] EXISTS" are you referring to?
If you mean the combination of column-level "IF [NOT] EXISTS" with
"COLUMN" omitted, then the first test above should be "ALTER FOREIGN TABLE
IF EXISTS doesnt_exist_ft1 ADD IF NOT EXISTS c5 integer"?

Regards,

-- 
Fujii Masao





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: DOC: fixes multiple errors in alter table doc
@ 2026-03-09 09:43  Fujii Masao <[email protected]>
  parent: Fujii Masao <[email protected]>
  0 siblings, 0 replies; 11+ messages in thread

From: Fujii Masao @ 2026-03-09 09:43 UTC (permalink / raw)
  To: Chao Li <[email protected]>; +Cc: Robert Treat <[email protected]>; Postgres hackers <[email protected]>

On Fri, Mar 6, 2026 at 4:53 PM Chao Li <[email protected]> wrote:
> PFA v6.

Thanks for updating the patch!

> The two test cases on table level “IF EXISTS” are removed. So, now the patch adds totally 4 test cases: 2 for omitting COLUMN, 2 for combinations of column level “IF [NOT] EXISTS” and omitting COUMN.

The latest patch doesn't seem to include the combination of column-level
IF NOT EXISTS for ADD COLUMN and omitting COLUMN.


Based on your patch, I updated the regression tests as follows and
pushed the changes:

+ALTER FOREIGN TABLE ft1 ADD c11 integer; -- omit COLUMN
+ALTER FOREIGN TABLE ft1 DROP c11; -- omit COLUMN

I moved the ALTER FOREIGN TABLE DROP test into the section that lists the other
existing ALTER FOREIGN TABLE DROP COLUMN tests.

Regarding table-level IF EXISTS tests, it seemed to me that most
ALTER FOREIGN TABLE ADD/DROP variants should also be tested there,
following the existing structure in foreign_data.sql. So I added some
additional cases, for example ALTER FOREIGN TABLE IF EXISTS ADD COLUMN IF
NOT EXISTS.

Regards,

-- 
Fujii Masao





^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2026-03-09 09:43 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 02:48 [PATCH 1/5] bootstrap: convert Typ to a List* Justin Pryzby <[email protected]>
2025-12-18 07:22 DOC: fixes multiple errors in alter table doc Chao Li <[email protected]>
2025-12-19 05:26 ` Re: DOC: fixes multiple errors in alter table doc Chao Li <[email protected]>
2026-01-22 09:38 ` Re: DOC: fixes multiple errors in alter table doc Chao Li <[email protected]>
2026-03-02 09:04   ` Re: DOC: fixes multiple errors in alter table doc Fujii Masao <[email protected]>
2026-03-02 09:22     ` Re: DOC: fixes multiple errors in alter table doc Chao Li <[email protected]>
2026-03-03 02:09       ` Re: DOC: fixes multiple errors in alter table doc Chao Li <[email protected]>
2026-03-03 04:41         ` Re: DOC: fixes multiple errors in alter table doc Robert Treat <[email protected]>
2026-03-05 04:42           ` Re: DOC: fixes multiple errors in alter table doc Fujii Masao <[email protected]>
2026-03-06 06:40             ` Re: DOC: fixes multiple errors in alter table doc Fujii Masao <[email protected]>
2026-03-09 09:43               ` Re: DOC: fixes multiple errors in alter table doc Fujii Masao <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox