Re: ALTER COLUMN SET EXPRESSION on partitions not work in case of constraint dependencies

From: Alberto Piai <alberto(dot)piai(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ALTER COLUMN SET EXPRESSION on partitions not work in case of constraint dependencies
Date: 2026-08-07 13:35:53
Message-ID: DKIR0GZPO0Y8.24FDHNPWCSWQL@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat Aug 1, 2026 at 7:57 AM CEST, jian he wrote:
> Hi.
>
> Reproducer:
>
> drop table if exists t;
> CREATE TABLE t (
> a int,
> b int GENERATED ALWAYS AS (NULLIF(a, 1)) STORED NOT NULL,
> constraint cc check (b > 0)) PARTITION BY RANGE (a);
> CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (10) TO (20);
> ALTER TABLE tp_0_1 ALTER COLUMN b SET EXPRESSION AS (a);
>
> -- expect two row, now nothing
> select conname, contype from pg_constraint where conrelid = 'tp_0_1'::regclass;

It's admittedly a long shot, since I'm still studying all of this, but:
what if, when we RememberConstraintForRebuilding() a constraint with
conislocal=false, we also RememberConstraintForRebuilding() its
corresponding parent constraint?

I have not fully considered the implications of this and I'm only
thinking about CHECK and NN constraints.

The attached patch is not meant for code-review, but just to illustrate
the idea and get the conversation started. What do you think?

Regards,

Alberto

--
Alberto Piai
Sensational AG
Zürich, Switzerland

Attachment Content-Type Size
nocfbot-v1-0001-WIP-fix-ATPostAlterTypeCleanup-dropping-constrain.patch text/plain 6.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Ashutosh Bapat 2026-08-07 13:25:49 Re: Error handling in after-startup shmem requests