| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | Vik Fearing <vik(at)postgresfriends(dot)org> |
| Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: implement CAST(expr AS type FORMAT 'template') |
| Date: | 2026-01-29 07:46:00 |
| Message-ID: | CACJufxGhOOYnPtmsuVocXVNyx2gB3K68ze67CM4LUqQeW--S8g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
hi.
Please check the attached new version.
I’ve integrated the CAST FORMAT logic right into coerce_to_target_type and
coerce_type, see static function coerce_type_with_format. in
coerce_type_with_format, we first first do source type, target type, format
expression check, validation, if everything is ok then, construct a FuncCall
node and let ParseFuncOrColumn do all the remaining job, with that now overall
the patch looks more neat.
I have tried to transform
SELECT CAST(NULL::text as time FORMAT NULL);
into
SELECT CAST( NULL::text AS timestamp with time zone FORMAT NULL::text)::time;
Then later realized it will not work, so CAST FORMAT can only be applied to the
result type of the following formatting functions: to_char, to_number, to_date,
or to_timestamp.
The tests are extensive. I put them right next to the to_char, to_number,
to_date, and to_timestamp tests so it's super easy to compare the results with
CAST FORMAT.
| Attachment | Content-Type | Size |
|---|---|---|
| v5-0001-CAST-expr-AS-type-FORMAT-template.patch | text/x-patch | 67.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alexander Korotkov | 2026-01-29 07:47:46 | Re: Implement waiting for wal lsn replay: reloaded |
| Previous Message | Amit Langote | 2026-01-29 07:35:13 | Re: Batching in executor |