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

From David G. Johnston
Subject Re: implement CAST(expr AS type FORMAT 'template')
Date
Msg-id CAKFQuwZXYxPw4wofq+zZ5D7nH0sHDBwr--qku9jWYv7dS+P8RQ@mail.gmail.com
Whole thread Raw
In response to Re: implement CAST(expr AS type FORMAT 'template')  (jian he <jian.universality@gmail.com>)
Responses Re: implement CAST(expr AS type FORMAT 'template')
List pgsql-hackers
On Monday, July 28, 2025, jian he <jian.universality@gmail.com> wrote:
On Mon, Jul 28, 2025 at 6:47 PM Vik Fearing <vik@postgresfriends.org> wrote:
>
> > adding these pg_cast entries seems tricky.

select proname, prosrc, proformat from pg_proc where proformat;

what do you think?

My first impression of this choice was not good.

How about changing the specification for create type.  Right now input functions must declare either 1 or 3 arguments.  Let’s also allow for 2 and 4-argument functions where the 2nd or 4th is where the format is passed.  If a data type input function lacks one of those signatures it is a runtime error if a format clause is attached to its cast expression.  For output, we go from having zero input arguments to zero or one, with the same resolution behavior.

Pass null for the format if the clause is missing or the cast is done via the :: operator, or any other context format is not able to be specified.

The slight variation to this would be to specify these 2/4 and 1-arg functions as optional “format_in” and “format_out” optional properties (like typmod_in).  The format-aware code can look for these which will end up having the full implementation while the current IO functions would simply stub out calls, passing null as the format. (Or maybe some variation that looks similar to typmod handling…which I haven’t looked at.)

David J.

pgsql-hackers by date:

Previous
From: Lukas Fittl
Date:
Subject: Re: Broken ./configure checks for __cpuid() and __cpuidex()
Next
From: Lukas Fittl
Date:
Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment