Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tVWJp-009C07-7U for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jan 2025 13:41:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tVWJo-001FFe-77 for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jan 2025 13:41:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tVWJn-001FFW-U2 for pgsql-hackers@lists.postgresql.org; Wed, 08 Jan 2025 13:41:55 +0000 Received: from fout-a5-smtp.messagingengine.com ([103.168.172.148]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tVWJk-000XZ3-1x for pgsql-hackers@postgresql.org; Wed, 08 Jan 2025 13:41:55 +0000 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 058FD138019D; Wed, 8 Jan 2025 08:41:52 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 08 Jan 2025 08:41:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm1; t=1736343712; x=1736430112; bh=/0AFN4z21MZ+Rvs0FHHdSHiJrwf6gA5k rFzn+DI+2as=; b=sG3Hbs9MIstXasIAzBLvT02V9QiGaBrw6bZ6KgJ9WoVbSLaR BQpIG9Mw0oZnvlf3ZPvmruBW+/hM4PXJIVAUnNInXNvgSXA81wW9w9DoL7x6EwBi 396rRhqtBhW6EqmK49capeJrn/A7oKA6PjkHI96ygJk6MODMbBSl25BJc3SLiaEV T8kRPHhJbmxxMXYs7zmWHaY+yFkQW73zCkbVhneRiCbm++Ydav8sKBSyva45wSDQ Fc3pRjV5GDilz6RiKvgy3W5PhAki3mNQSxSIXxxLnezqcMFP085efOd8ZleNg+0L S5ZLiW01PMUVns2382eJBeBlcbsyeY66gdGbMg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1736343712; x= 1736430112; bh=/0AFN4z21MZ+Rvs0FHHdSHiJrwf6gA5krFzn+DI+2as=; b=p jdPmqWJNkijX4O+ckk+qwX6p/FlybCvTZ9+IudAzUiPzOjufH2KAS8O2sfS27o2X w7zzotTXgI/g5Yr3z9qz2z4w8RpqeomZ9zoqcW24Eeu0mMwTUY+O0o+FZtVVLoCZ i/QvH6jRltEHYkohB0lGnH8lFo+nA6rT1T3i9/nrhzmXiU2EmP/L4m1+7PDClP7l Nq8p/hpaG1bxZWeYRJBabRUG2zhbUDUMC8LKwgwDV1cjqOB8sNQrMi+SwQuz7jpV NCtysDrcVxYon/z85qK/v1XsTyKDp0KYdI+FAe35puJf3z3WcAQCNLADCy7DG/5R 8Vj+BnnwYhWJlv4eQYpmQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeggedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpefrvghtvghrucfgihhsvghnthhrrghuthcuoehpvghtvghrsegvihhsvg hnthhrrghuthdrohhrgheqnecuggftrfgrthhtvghrnhepgfejtdfhkeeftdeugfeileeh teeljeeghfeuledthfeutedvffdukeefjefhgeehnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdho rhhgpdhnsggprhgtphhtthhopeegpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hguhhofhgvnhhglhhinhhugiesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhl qdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopehjihgrnh druhhnihhvvghrshgrlhhithihsehgmhgrihhlrdgtohhmpdhrtghpthhtohepuggvrghn rdgrrdhrrghshhgvvggusehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 8 Jan 2025 08:41:51 -0500 (EST) Message-ID: <0aefea9d-9cab-47b5-985f-91eb4b02bb74@eisentraut.org> Date: Wed, 8 Jan 2025 14:41:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Virtual generated columns To: Richard Guo Cc: pgsql-hackers , jian he , Dean Rasheed References: <732a9543-0312-4f0c-a471-857b507a3546@eisentraut.org> <0f811f71-8c86-4e1b-b3bb-6a535674a440@eisentraut.org> <09800cb1-43aa-4239-8918-46b71ede4900@eisentraut.org> <536b281b-2cb3-4477-971f-c64838bc6263@eisentraut.org> <51875199-d5f5-41ed-92dc-3e7b1b996991@eisentraut.org> Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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.