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 1ueC4p-006FTf-9D for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 12:26:36 +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 1ueC4o-007O8b-73 for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 12:26:34 +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 1ueC4n-007O8S-Nk for pgsql-hackers@lists.postgresql.org; Tue, 22 Jul 2025 12:26:34 +0000 Received: from relay1-d.mail.gandi.net ([2001:4b98:dc4:8::221]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ueC4j-000Dy6-24 for pgsql-hackers@lists.postgresql.org; Tue, 22 Jul 2025 12:26:33 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 59DBF43A2B; Tue, 22 Jul 2025 12:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=postgresfriends.org; s=gm1; t=1753187186; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Qozeq2FotNyKD2LZ1AdazT48i6+isU7z/knnqmykTs=; b=hqvMrLxuseSrtxnB9uhfeg9Y5qtOLQDsDWMYrPO6nPT6PsoA3yiePfi1u1x4UAN6Nr4Ymu Of2nuLCouifHKu1TOBkVojbDeg8hxvDUjMFZ9V+JyYbjXgZ57QbYF8M7SVvkzAbd4V9PuN xWFqEbfk2DPlU8xFBK5qtH/MHF0HpKgqWzMqiEnE+YcXf7LdayevnY3gU+kMEhKQDqI4f7 OVH2Jrsh9TLugekmw3SbV+UZdbfYeuEOaMul/JjZ7b58Co1+h2HXl72jg4d3tnszsvY65m FLcLnA56uaV/o2SxBbjTf+zIkZtXDf+FCLuUlPsVOWzC8DJfw3MdA0bvN1IaBQ== Message-ID: <762ae707-7fdc-43d8-a77a-3a10d12ce21d@postgresfriends.org> Date: Tue, 22 Jul 2025 14:26:25 +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> Content-Language: en-US From: Vik Fearing In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejgeeklecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeggihhkucfhvggrrhhinhhguceovhhikhesphhoshhtghhrvghsfhhrihgvnhgushdrohhrgheqnecuggftrfgrthhtvghrnhepuddtveefleegvddutdejhffhleehhfevheeilefhgeettdeuhfdtffegvdfgteffnecukfhppedvrgdtvdemkeegvdekmeduudgvtdemvdejtddumegrgegvudemgedvfhegmegrlegrkeemkegvieeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdgrtddvmeekgedvkeemudduvgdtmedvjedtudemrgegvgdumeegvdhfgeemrgelrgekmeekvgeikedphhgvlhhopeglkffrggeimedvrgdtvdemkeegvdekmeduudgvtdemvdejtddumegrgegvudemgedvfhegmegrlegrkeemkegvieekngdpmhgrihhlfhhrohhmpehvihhksehpohhsthhgrhgvshhfrhhivghnughsrdhorhhgpdhnsggprhgtphhtthhopeegpdhrtghpthhtohepjhhirghnrdhunhhivhgvrhhsrghlihhthiesghhmrghilhdrtghomhdprhgtphhtthhopegtohhrvgihrdhhuhhinhhkvghrsehgmhgrihhlrdgtohhmpdhrt ghpthhtohepihhsrggrtgdrmhhorhhlrghnugesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-GND-Sasl: vik@postgresfriends.org List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 22/07/2025 12:19, jian he wrote: > On Tue, Jul 22, 2025 at 2:45 PM Vik Fearing wrote: >> It was accepted into the standard after 2023 was released. I am the >> author of this change in the standard, so feel free to ask me anything >> you're unsure about. >> > is the generally syntax as mentioned in this thread: > CAST(source_expression AS target_type DEFAULT default_expression ON ERROR) > > if so, what's the restriction of default_expression? The actual syntax is: ::=     CAST         AS         [ FORMAT ]         [ ON CONVERSION ERROR ]         "CONVERSION" is probably a noise word, but it is there because A) Oracle wanted it there, and B) it makes sense because if the fails, that is still a failure of the entire CAST. The is: ::=     ERROR   | NULL   | DEFAULT but I am planning on removing the NULL variant in favor of having the be a .  So it would be either ERROR ON CONVERSION ERROR (postgres's current behavior), or DEFAULT NULL ON CONVERSION ERROR. An example of B) above would be: CAST('five' AS INTEGER DEFAULT 'six' ON CONVERSION ERROR).  'six' is no more an integer than 'five' is, so that would error out because the conversion error does not happen on the operand but on the default clause. CAST('five' AS INTEGER DEFAULT 6 ON CONVERSION ERROR) would work. -- Vik Fearing