Re: Why cannot alter a column's type when it's used by a generated column - Mailing list pgsql-hackers

From Chao Li
Subject Re: Why cannot alter a column's type when it's used by a generated column
Date
Msg-id F9640008-0A95-410E-8647-8FA1F94453A7@gmail.com
Whole thread Raw
In response to Re: Why cannot alter a column's type when it's used by a generated column  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers

> 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/





Attachment

pgsql-hackers by date:

Previous
From: David Klika
Date:
Subject: Re: Adding REPACK [concurrently]
Next
From: Dilip Kumar
Date:
Subject: Re: Proposal: Conflict log history table for Logical Replication