From 5fa11495a4e7b10755a4017d8e1498435ae3e507 Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" 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 Reviewed-by: Fujii Masao Reviewed-by: Robert Treat 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 numeric_literal, REM - ADD COLUMN [ IF NOT EXISTS ] + ADD [ COLUMN ] [ IF NOT EXISTS ] This form adds a new column to the table, using the same syntax as @@ -175,7 +175,7 @@ WITH ( MODULUS numeric_literal, REM - DROP COLUMN [ IF EXISTS ] + DROP [ COLUMN ] [ IF EXISTS ] 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)