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 1ueweN-00GzKA-VR for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 14:10:24 +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 1ueweM-008GYk-QU for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 14:10:23 +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 1ueweM-008GYb-F6 for pgsql-hackers@lists.postgresql.org; Thu, 24 Jul 2025 14:10:22 +0000 Received: from relay1-d.mail.gandi.net ([217.70.183.193]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ueweI-000c6o-39 for pgsql-hackers@lists.postgresql.org; Thu, 24 Jul 2025 14:10:22 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id BDA144434A; Thu, 24 Jul 2025 14:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=postgresfriends.org; s=gm1; t=1753366217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dRnub47m1k2LHevu2Q5Whnbyl70sE1lm+7R/BG7Wksc=; b=Q+GAi27WGheik2ihon6PseYgo0KsAcGwhnyxqC9/HWxws4RQOBbC7fr2k0Zx/1haPx2z4a e31iAGHC1hrza0sYPw6/WoTy+BFj2+giCarhL0rCx++oitPiJkFXXtwGZm+FZ4Hw8cGmIw 2h3NGorA+UQ0WYlzGrd0KpSO52zL6zS7Y9firx7KMePvp4IVFNHB+u+4K54njAhBBCObF8 e5OdYndE/7BxMXsZZ06LXn3OV2lTdgFRT9zhmm5uFAoTbzKw7DCDrL1rx28Az82kqEBGEm oBFLRYsYomiDb85CzOQgvJshgz6M7snwx1iiAtYGkTYry2mFq4yWlzU6zY0eug== Content-Type: multipart/alternative; boundary="------------rVLstx8bt7EG0O4n4DO8dzvR" Message-ID: <0aa52082-152c-41d3-ac32-07818497afcd@postgresfriends.org> Date: Thu, 24 Jul 2025 16:10:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions To: jian he Cc: Corey Huinker , Isaac Morland , pgsql-hackers@lists.postgresql.org References: <04afcd1f-ed7d-4c0a-add1-50e3719ccbf9@postgresfriends.org> <762ae707-7fdc-43d8-a77a-3a10d12ce21d@postgresfriends.org> Content-Language: en-US From: Vik Fearing In-Reply-To: X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdektdekhecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurheptgfkffggfgfuvfevfhfhjgesrgdtreertddvjeenucfhrhhomhepgghikhcuhfgvrghrihhnghcuoehvihhksehpohhsthhgrhgvshhfrhhivghnughsrdhorhhgqeenucggtffrrghtthgvrhhnpefgjeefudffffeljeeutdejffffteejuefhteekheehkedtjeektdegjeeggffhtdenucfkphepvdgrtddvmeekgedvkeemudduvgdtmedvjedtudemudguudelmeelhegtkeemudelrgdumeekieekvgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtvdemkeegvdekmeduudgvtdemvdejtddumeduugduleemleehtgekmedulegrudemkeeikegvpdhhvghloheplgfkrfggieemvdgrtddvmeekgedvkeemudduvgdtmedvjedtudemudguudelmeelhegtkeemudelrgdumeekieekvggnpdhmrghilhhfrhhomhepvhhikhesphhoshhtghhrvghsfhhrihgvnhgushdrohhrghdpnhgspghrtghpthhtohepgedprhgtphhtthhopehjihgrnhdruhhnihhvvghrshgrlhhithihsehgmhgrihhlrdgtohhmpdhrtghpthhtoheptghorhgvhidrhhhuihhnkhgvrhesghhmrghilhdrtghomhdprhgtp hhtthhopehishgrrggtrdhmohhrlhgrnhgusehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-GND-Sasl: vik@postgresfriends.org List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------rVLstx8bt7EG0O4n4DO8dzvR Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 24/07/2025 03:22, jian he wrote: > +SELECT CAST('a' as int DEFAULT sum(1) ON CONVERSION ERROR); --error > +SELECT CAST('a' as int DEFAULT sum(1) over() ON CONVERSION ERROR); --error This seems like an arbitrary restriction.  Can you explain why this is necessary?  Those same expressions are allowed as the . > +SELECT CAST('a' as int DEFAULT ret_setint() ON CONVERSION ERROR) --error > (ret_setint function is warped as (select 1 union all select 2)) This makes sense to me. > for array coerce, which you already mentioned, i think the following > is what we expected. > +SELECT CAST('{234,def,567}'::text[] AS integer[] DEFAULT '{-1011}' ON > CONVERSION ERROR); > + int4 > +--------- > + {-1011} > +(1 row) Yes, that looks correct to me. > I didn't implement the [ FORMAT ] part for now. That is fine, since it's separate feature > please check the attached regress test and tests expected result. Except for the weird restriction on the default value, this all looks good to me (with the usual caveat that I am not an expert in C). Are you planning to also implement the ? -- Vik Fearing --------------rVLstx8bt7EG0O4n4DO8dzvR Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 24/07/2025 03:22, jian he wrote:
+SELECT CAST('a' as int DEFAULT sum(1) ON CONVERSION ERROR); --error
+SELECT CAST('a' as int DEFAULT sum(1) over() ON CONVERSION ERROR); --error


This seems like an arbitrary restriction.  Can you explain why this is necessary?  Those same expressions are allowed as the <cast operand>.


+SELECT CAST('a' as int DEFAULT ret_setint() ON CONVERSION ERROR) --error
(ret_setint function is warped as (select 1 union all select 2))


This makes sense to me.


for array coerce, which you already mentioned, i think the following
is what we expected.
+SELECT CAST('{234,def,567}'::text[] AS integer[] DEFAULT '{-1011}' ON
CONVERSION ERROR);
+  int4
+---------
+ {-1011}
+(1 row)


Yes, that looks correct to me.


I didn't implement the [ FORMAT <cast template> ] part for now.


That is fine, since it's separate feature


please check the attached regress test and tests expected result.


Except for the weird restriction on the default value, this all looks good to me (with the usual caveat that I am not an expert in C).


Are you planning to also implement the <castable predicate>?

-- 

Vik Fearing

--------------rVLstx8bt7EG0O4n4DO8dzvR--