From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | jian he <jian(dot)universality(at)gmail(dot)com> |
Cc: | Vik Fearing <vik(at)postgresfriends(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: implement CAST(expr AS type FORMAT 'template') |
Date: | 2025-08-04 03:36:00 |
Message-ID: | CAKFQuwaG00tsXc2oSQwjdSnPQ=JuH+T8Oeejb3sO5TeqUHsfUQ@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sun, Aug 3, 2025 at 8:10 PM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
> hi.
> one more question:
>
> For binary coercible type casts, no formatted related function for it,
> should we error out?
> For example, should the following error out or return text '1'.
>
> select cast('1'::text as text format 'YYYY'::text);
>
I'm hoping the standard says (or allows us to) error out here.
text as a type has no semantics on which to associate a format so it
should be an error to attempt to do so. Not a silent no-op.
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.
IME we are actually implementing a formatting option for text serialization
and deserialization here, not a cast (we are just borrowing existing syntax
that is serviceable). Hence the absence of these entries in pg_cast and
why the fit into pg_type seems so reasonable.
The existence of the various "to_char" and "to_date" functions reflects the
historical lack of a dedicated syntax for this kind of (de-)serialization.
But it seems unwise to bias ourselves to how the new syntax/feature should
be implemented just because these functions exist. At least one design
should be done pretending they don't and see what comes out of it. Their
code can always be moved or reused in whatever we come up with; forcing
them to be used directly, as-is, within the new solution adds an
unnecessary constraint.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Tender Wang | 2025-08-04 03:41:35 | Re: A little cosmetic to convert_VALUES_to_ANY() |
Previous Message | Dilip Kumar | 2025-08-04 03:30:32 | Re: Conflict detection for update_deleted in logical replication |