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

From jian he
Subject Re: implement CAST(expr AS type FORMAT 'template')
Date
Msg-id CACJufxGhOOYnPtmsuVocXVNyx2gB3K68ze67CM4LUqQeW--S8g@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
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.



--
jian
https://www.enterprisedb.com/

Attachment

pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: Batching in executor
Next
From: Alexander Korotkov
Date:
Subject: Re: Implement waiting for wal lsn replay: reloaded