Re: Virtual generated columns - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Virtual generated columns
Date
Msg-id 0aefea9d-9cab-47b5-985f-91eb4b02bb74@eisentraut.org
Whole thread Raw
In response to Re: Virtual generated columns  (Richard Guo <guofenglinux@gmail.com>)
List 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.



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Moving the vacuum GUCs' docs out of the Client Connection Defaults section
Next
From: Frédéric Yhuel
Date:
Subject: Re: New GUC autovacuum_max_threshold ?