Re: Virtual generated columns

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, jian he <jian(dot)universality(at)gmail(dot)com>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Subject: Re: Virtual generated columns
Date: 2025-01-08 13:41:50
Message-ID: 0aefea9d-9cab-47b5-985f-91eb4b02bb74@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 08.01.25 09:22, Richard Guo wrote:
>> - Added support for ALTER TABLE ... SET EXPRESSION.
> When using ALTER TABLE to set expression for virtual generated
> columns, we don't enforce a rewrite, which means we don't have the
> opportunity to check whether the new values for these columns could
> cause an underflow or overflow. For instance,
>
> create table t (a int, b int generated always as (a) virtual);
> insert into t values (2147483647);
>
> # alter table t alter column b set expression as (a * 2);
> ALTER TABLE
>
> # select * from t;
> ERROR: integer out of range
>
> The same thing could occur with INSERT. As we don't compute virtual
> generated columns on write, we may end up inserting values that cause
> underflow or overflow for these columns.
>
> create table t1 (a int, b int generated always as (a * 2) virtual);
> insert into t1 values (2147483647);
>
> # select * from t1;
> ERROR: integer out of range
>
> I'm not sure if this is expected or not, so I just wanted to point it
> out.

Yes, this is expected behavior. This also happens with a view. So it
is consistent for compute-on-read objects.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2025-01-08 13:43:57 Re: psql: Option to use expanded mode for various meta-commands
Previous Message Peter Eisentraut 2025-01-08 13:39:26 Re: Moving the vacuum GUCs' docs out of the Client Connection Defaults section