[patch] ALTER COLUMN SET EXPRESSION [GENERATED|STORED]

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: [patch] ALTER COLUMN SET EXPRESSION [GENERATED|STORED]
Date: 2025-08-28 04:00:57
Message-ID: CACJufxGXLU400QBBgdoboaza0xK58rQqsCAPrxbAMUmo0f8xCQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.
I realized that we can also modify attgenerated when updating the generated
expression using ALTER COLUMN SET EXPRESSION.
so POC attached.

I have also considered using ALTER TABLE ALTER COLUMN STORED/VIRTUAL
to change attgenerated,
but since we can update both the generated expression and attgenerated
simultaneously, extending ALTER COLUMN SET EXPRESSION seems more better
than ALTER COLUMN {STORED|VIRTUAL}

example syntax explanation:
ALTER TABLE gtest29 ALTER COLUMN b SET EXPRESSION AS (a * 3);
exists syntax, nothing changed.

ALTER TABLE gtest29 ALTER COLUMN b SET EXPRESSION AS (a * 3) STORED;
column b attgenerated will be set to ATTRIBUTE_GENERATED_STORED,
table rewrite will happen.

ALTER TABLE gtest29 ALTER COLUMN b SET EXPRESSION AS (a * 3) VIRTUAL;
column b attgenerated will set to ATTRIBUTE_GENERATED_VIRTUAL,
table rewrite will not happen. (VACUUM FULL will make that column
values as 0, isnull as true).

what do you think?

Attachment Content-Type Size
v1-0001-ALTER-COLUMN-SET-EXPRESSION-GENERATED-STORED.patch text/x-patch 50.4 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2025-08-28 04:14:34 Re: Potential problem in commit f777d773878 and 4f7f7b03758
Previous Message jian he 2025-08-28 03:34:52 Re: Fix ALTER TABLE DROP EXPRESSION with inheritance hierarchy