Re: implement CAST(expr AS type FORMAT 'template') - Mailing list pgsql-hackers

From Vik Fearing
Subject Re: implement CAST(expr AS type FORMAT 'template')
Date
Msg-id 82b4223e-84d4-432d-8167-dd698ce489f5@postgresfriends.org
Whole thread Raw
In response to Re: implement CAST(expr AS type FORMAT 'template')  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-hackers


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

pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: GB18030-2022 Support in PostgreSQL
Next
From: Andrew Dunstan
Date:
Subject: Re: split func.sgml to separated individual sgml files