Re: Why cannot alter a column's type when it's used by a generated column
Chao Li <li.evan.chao@gmail.com>
From: Chao Li <li.evan.chao@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: Peter Eisentraut <peter@eisentraut.org>
Date: 2025-12-08T09:18:35Z
Lists: pgsql-hackers
Attachments
- v3-0001-Alow-ALTER-COLUMN-TYPE-when-dependent-generated-c.patch (application/octet-stream) patch v3-0001
- (unnamed) (text/plain)
> On Oct 22, 2025, at 16:57, Chao Li <li.evan.chao@gmail.com> wrote:
>
>
> ```
> % make check
> …
> 1..230
> # All 230 tests passed.
> ```
>
> Rebased v2 attached.
>
Bump. And rebased to v3.
When you have a column that is used by a generated column, if you need to alter type of the column:
```
-- Before this patch, the recommended usage was:
ALTER TABLE gtest
DROP COLUMN x,
ALTER COLUMN a TYPE float8,
ADD COLUMN x bigint GENERATED ALWAYS AS ((a::int + b) * 2) STORED;
-- With this patch, the statement is simplified as:
ALTER TABLE gtest
ALTER COLUMN a TYPE float8,
ALTER COLUMN x SET EXPRESSION ((a::int + b) * 2);
```
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/