Re: Why cannot alter a column's type when it's used by a generated column

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Re: Why cannot alter a column's type when it's used by a generated column
Date: 2025-12-08 09:18:35
Message-ID: F9640008-0A95-410E-8647-8FA1F94453A7@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Oct 22, 2025, at 16:57, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)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/

Attachment Content-Type Size
v3-0001-Alow-ALTER-COLUMN-TYPE-when-dependent-generated-c.patch application/octet-stream 11.6 KB
unknown_filename text/plain 4 bytes

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2025-12-08 09:30:47 Re: Proposal: Conflict log history table for Logical Replication
Previous Message David Klika 2025-12-08 09:13:20 Re: Adding REPACK [concurrently]