| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | jian he <jian(dot)universality(at)gmail(dot)com> |
| Cc: | Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org> |
| Subject: | Re: Fix SET EXPRESSION for virtual columns with whole-row dependencies |
| Date: | 2026-06-10 09:12:58 |
| Message-ID: | B9D7A867-DE2D-4E7D-907D-0F9E26C3D8B3@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Jun 10, 2026, at 17:05, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
>
>
>> On Jun 9, 2026, at 15:28, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>>
>>
>>
>>> On Jun 9, 2026, at 15:23, jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>>>
>>> On Tue, Jun 9, 2026 at 2:23 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> While testing “[f80bedd52] Allow ALTER COLUMN SET EXPRESSION on virtual columns”, I found that the feature missed handling whole-row check constraints.
>>>>
>>>> Here is a repro:
>>>> ```
>>>> evantest=# create table t(
>>>> evantest(# a int,
>>>> evantest(# b int generated always as (a*2) virtual,
>>>> evantest(# constraint row_c check (t is not null)
>>>> evantest(# );
>>>> CREATE TABLE
>>>> evantest=# insert into t(a) values(1);
>>>> INSERT 0 1
>>>> evantest=# alter table t alter b set expression as (nullif(a, 1));
>>>> ALTER TABLE
>>>> evantest=# select * from t;
>>>> a | b
>>>> ---+---
>>>> 1 |
>>>> (1 row)
>>>> ```
>>>>
>>>> The ALTER TABLE should fail, because it makes b become NULL, which breaks the constraint row_c.
>>>>
>>>
>>> Hi.
>>>
>>> In case you are wondering whole-row objects:
>>> ALTER TABLE DROP COLUMN and ALTER COLUMN SET DATA TYPE are covered by
>>> https://commitfest.postgresql.org/patch/5988 and
>>> https://commitfest.postgresql.org/patch/6055.
>>>
>>> Meanwhile, ALTER TABLE SET EXPRESSION is being handled over in
>>> https://commitfest.postgresql.org/patch/6755
>>
>> Thanks for pointing out that. I will review 6755.
>>
>> Best regards,
>> --
>> Chao Li (Evan)
>> HighGo Software Co., Ltd.
>> https://www.highgo.com/
>>
>
> After reading the other implementation in [1], I realized that I had missed the partial-index case, so I added coverage for that.
>
> I am still sending an updated version of this patch because my implementation is different from the one in [1]. I would like people to compare the two approaches and decide which direction is better.
>
> [1] https://postgr.es/m/CAJTYsWXOkyeDVbzymWc9sKrq7Y_MUv6XJXN4H9GfsBOPd3NJ+w@mail.gmail.com
>
> Best regards,
> --
> Chao Li (Evan)
> HighGo Software Co., Ltd.
> https://www.highgo.com/
>
>
Oops! Forgot the attachment. Here comes it.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fix-SET-EXPRESSION-with-whole-row-virtual-column-.patch | application/octet-stream | 13.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chao Li | 2026-06-10 09:15:38 | Re: [PATCH] Rebuild CHECK constraints after generated column SET EXPRESSION |
| Previous Message | Rafia Sabih | 2026-06-10 09:08:48 | Re: postgres_fdw: Emit message when batch_size is reduced |