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 1uiulJ-0000GB-L4 for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Aug 2025 12:57:58 +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 1uiulH-001Hjc-KI for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Aug 2025 12:57:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uiulG-001HjU-SM for pgsql-hackers@lists.postgresql.org; Mon, 04 Aug 2025 12:57:55 +0000 Received: from relay15.mail.gandi.net ([217.70.178.235]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uiulD-000gaj-1F for pgsql-hackers@postgresql.org; Mon, 04 Aug 2025 12:57:53 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 52A6544215; Mon, 4 Aug 2025 12:57:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=postgresfriends.org; s=gm1; t=1754312269; 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=FtrkmTXhM2brsJvrM3vyc6Ckb2Kz3aWeEtYbCaiZBiU=; b=jXA5WBAG3CPxHMVhvIfOFMfXqY18taZBRgXQ9VHlbCok08AGHnJwH1V1RjFoDUocLS0MqW 5gBkVSQK2TFOR8gx3EOzOnU4Q1CvUz2kONXnnkGPS3uxbM4Tmgw5Zk2H3UWdrBP+TqpMGX Dt5Hk5/iNoVOiI7HPnnCq6U2R0kSP7ib6kknqc4L0OXw3Oblp0/rAcWi7rzB+SzVE2h88Y cvRT53GSjZzqPbr8BmzfTWhhp8YO+H2CcVCSz5XUiv3jZ4TGiyXAhwyaSU7b8YPD9nnTAk pieIht6Z3wFceCkSOq+Sua/5B0uR3flsrhlSje4JC/ZoBbhZM5Rs44kV7wEqxA== Content-Type: multipart/alternative; boundary="------------hhbu80YwMFHlsRfP64EKlyID" Message-ID: <82b4223e-84d4-432d-8167-dd698ce489f5@postgresfriends.org> Date: Mon, 4 Aug 2025 14:57:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: implement CAST(expr AS type FORMAT 'template') To: "David G. Johnston" , Corey Huinker Cc: jian he , PostgreSQL-development References: <4c358bf8-87e8-4760-83d5-a6f9fcd88907@postgresfriends.org> <1b702de4-86b0-4144-a2d0-38266296894f@postgresfriends.org> Content-Language: en-US From: Vik Fearing In-Reply-To: X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduuddvfeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpegtkfffgggfuffvvehfhfgjsegrtderredtvdejnecuhfhrohhmpeggihhkucfhvggrrhhinhhguceovhhikhesphhoshhtghhrvghsfhhrihgvnhgushdrohhrgheqnecuggftrfgrthhtvghrnhepgfejfeduffffleejuedtjeffffetjeeuhfetkeehheektdejkedtgeejgefghfdtnecukfhppedvrgdtgeemtggvtgdtmedutdguheemfedvtdegmeekhegvvgemfhdtheemtggvrgefmeguiegsfhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtgeemtggvtgdtmedutdguheemfedvtdegmeekhegvvgemfhdtheemtggvrgefmeguiegsfhdphhgvlhhopeglkffrggeimedvrgdtgeemtggvtgdtmedutdguheemfedvtdegmeekhegvvgemfhdtheemtggvrgefmeguiegsfhgnpdhmrghilhhfrhhomhepvhhikhesphhoshhtghhrvghsfhhrihgvnhgushdrohhrghdpnhgspghrtghpthhtohepgedprhgtphhtthhopegurghvihgurdhgrdhjohhhnhhsthhonhesghhmrghilhdrtghomhdprhgtphhtthhopegtohhrvgihrdhhuhhinhhkvghrsehgmhgrihhlrdgtohhmpdhrtghpthhto hepjhhirghnrdhunhhivhgvrhhsrghlihhthiesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhrgh 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. --------------hhbu80YwMFHlsRfP64EKlyID Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 04/08/2025 07:55, David G. Johnston wrote: > On Sunday, August 3, 2025, Corey Huinker wrote: > > On Sun, Aug 3, 2025 at 11:36 PM David G. Johnston > wrote: > > > I was under the impression that for format to be allowed in > the expression one of the two data types involved has to be > text and the other must not be text. > > > I hadn't understood that, but also hadn't thought of a case where > it might be wanted until just now. What if someone wanted a cast > from JSONB to their custom type, and the format was a specific > keypath to extract from the JSONB? It's true that could be > accomplished by first extracting the keypath and then CASTing that > expression, but the same is true for text->date, regexing a > YYYY-MM-DD into the locale default. > > > Feels like the same basic answer.  Create cast has a single (because > it’s one-way) function accepting between 1 and 3 arguments.  Change it > to accept between 1 and 4 arguments and the 4th is where the format > expression gets passed.  If a format expression is present and the > function doesn’t have a 4th argument, error. This is my position as well. +1 -- Vik Fearing --------------hhbu80YwMFHlsRfP64EKlyID Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 04/08/2025 07:55, David G. Johnston wrote:
On Sunday, August 3, 2025, Corey Huinker <corey.huinker@gmail.com> wrote:
On Sun, Aug 3, 2025 at 11:36 PM David G. Johnston <david.g.johnston@gmail.com> wrote:

I was under the impression that for format to be allowed in the expression one of the two data types involved has to be text and the other must not be text.

I hadn't understood that, but also hadn't thought of a case where it might be wanted until just now. What if someone wanted a cast from JSONB to their custom type, and the format was a specific keypath to extract from the JSONB? It's true that could be accomplished by first extracting the keypath and then CASTing that expression, but the same is true for text->date, regexing a YYYY-MM-DD into the locale default.

Feels like the same basic answer.  Create cast has a single (because it’s one-way) function accepting between 1 and 3 arguments.  Change it to accept between 1 and 4 arguments and the 4th is where the format expression gets passed.  If a format expression is present and the function doesn’t have a 4th argument, error.


This is my position as well.

+1

-- 

Vik Fearing

--------------hhbu80YwMFHlsRfP64EKlyID--