Subject: pgsql: Allow ALTER COLUMN SET EXPRESSION on virtual columns with CHECK

From: Peter Eisentraut <[email-masked]>
Date: Tue, 24 Feb 2026 09:42:06 +0000

Allow ALTER COLUMN SET EXPRESSION on virtual columns with CHECK constraints

Previously, changing the generation expression of a virtual column was
prohibited if the column was referenced by a CHECK constraint.  This
lifts that restriction.

RememberAllDependentForRebuilding within ATExecSetExpression will
rebuild all the dependent constraints, later ATPostAlterTypeCleanup
queues the required AlterTableStmt operations for ALTER TABLE Phase 3
execution.

Overall, ALTER COLUMN SET EXPRESSION on virtual columns may require
scanning the table to re-verify any associated CHECK constraints, but
it does not require a table rewrite in ALTER TABLE Phase 3.

Author: jian he <[email-masked]>
Reviewed-by: Matheus Alcantara <[email-masked]>
Discussion: https://postgr.es/m/[email-masked]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f80bedd52b1501de51b7180cd817e3e1fc31429d

Modified Files
--------------
doc/src/sgml/ref/alter_table.sgml               |  3 ++
src/backend/commands/tablecmds.c                | 25 ++++------------
src/test/regress/expected/generated_virtual.out | 39 +++++++++++++++++++++----
src/test/regress/sql/generated_virtual.sql      | 16 ++++++++--
4 files changed, 56 insertions(+), 27 deletions(-)

---

From: Erik Rijkers <[email-masked]>
Date: Thu, 26 Feb 2026 15:16:22 +0100

Op 2/24/26 om 10:42 schreef Peter Eisentraut:
> [...]

Hi,

Typo in doc/src/sgml/ref/alter_table.sgml:

-      Replacing the expression of a virtual generated column do not 
require a
+      Replacing the expression of a virtual generated column does not 
require a

Thanks,

Erik

--- doc/src/sgml/ref/alter_table.sgml.orig	2026-02-26 15:04:21.054592120 +0100
+++ doc/src/sgml/ref/alter_table.sgml	2026-02-26 15:05:24.878594162 +0100
@@ -278,7 +278,7 @@
       This form replaces the expression of a generated column.  Existing data
       in a stored generated column is rewritten and all the future changes
       will apply the new generation expression.
-      Replacing the expression of a virtual generated column do not require a
+      Replacing the expression of a virtual generated column does not require a
       table rewrite, but if the column is used in a constraint, the table will
       be scanned to check that existing rows meet the constraint.
      </para>

---

From: Chao Li <[email-masked]>
Date: Fri, 27 Feb 2026 07:21:01 +0800

> On Feb 26, 2026, at 22:16, Erik Rijkers <[email-masked]> wrote:
> 
> <alter_table.sgml.20260226.diff>

“Do” -> “does”, looks like a correct grammar fix to me.

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

---

From: Michael Paquier <[email-masked]>
Date: Mon, 2 Mar 2026 11:35:02 +0900

> +      Replacing the expression of a virtual generated column does not

Thanks.  This applies only to HEAD.  Grabbed that for later.
--
Michael