Обсуждение: [patch] ALTER COLUMN SET EXPRESSION [GENERATED|STORED]

Поиск
Список
Период
Сортировка

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

От
jian he
Дата:
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?

Вложения

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

От
jian he
Дата:
On Thu, Aug 28, 2025 at 12:00 PM jian he <jian.universality@gmail.com> wrote:
>
> hi.
> I realized that we can also modify attgenerated when updating the generated
> expression using ALTER COLUMN SET EXPRESSION.
> so POC attached.
>

hi.

rebased with minor updates to comments and test cases.


--
jian
https://www.enterprisedb.com/

Вложения

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

От
jian he
Дата:
hi.

I found a use case for this patch:
If you want to change a column from stored to virtual, or from virtual to
stored, you previously had to drop the column and re-add it as a stored or
virtual generated column. This would break all existing dependencies, requiring
them to be recreated from scratch. With this patch, the process is much more
convenient, as RememberAllDependentForRebuilding is used internally to rebuild
all dependencies automatically.

A rebased patch is attached.


--
jian
https://www.enterprisedb.com/

Вложения