public inbox for [email protected]  
help / color / mirror / Atom feed
From: Peter Eisentraut <[email protected]>
To: Richard Guo <[email protected]>
Cc: pgsql-hackers <[email protected]>
Cc: jian he <[email protected]>
Cc: Dean Rasheed <[email protected]>
Subject: Re: Virtual generated columns
Date: Wed, 8 Jan 2025 14:41:50 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAMbWs48Ki7vScBfO0_JD_LTFPwbS-Vi-HKqQfg8ZK34OL0APKg@mail.gmail.com>
References: <[email protected]>
	<CACJufxHxoz_KVQxcQ=cSvJc+PNbh=FaHbcMZCOisoOaGAgjy4w@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CAEZATCV=RX0M58-uqSR6tFjwQAFnEcx3hvW-9ZZfRQJLg5LzRw@mail.gmail.com>
	<[email protected]>
	<CAEZATCU3q=znAL7X1aSxuMpjfSyB1cT5j398HPb9ix9ci_HUqA@mail.gmail.com>
	<[email protected]>
	<CAEZATCVLfMzNwT1J0bnvtv6YbmNSN9QSXb+1QSGyX6vK4q67Ow@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAEZATCUHnmOu7RtDuP+PCtS_dqvU8hFsAYYFPdiB8gyFszj5WQ@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CAMbWs48Ki7vScBfO0_JD_LTFPwbS-Vi-HKqQfg8ZK34OL0APKg@mail.gmail.com>

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.






view thread (75+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Virtual generated columns
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox