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

From zengman
Subject Re: implement CAST(expr AS type FORMAT 'template')
Date
Msg-id tencent_73665D4D79A6E8901E43082F@qq.com
Whole thread Raw
In response to Re: implement CAST(expr AS type FORMAT 'template')  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
> 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.

Hi,

This patch looks great, and the tests run well. I found a few minor details,
that you might consider fixing:

Typos
- parse_expr.c:2745: "formmatted" → "formatted"
- parse_coerce.c:156: "Cocerce" → "Coerce"

In `coerce_type_with_format()` (parse_coerce.c):

1. The check `if (fmtcategory != TYPCATEGORY_STRING && fmtcategory != TYPCATEGORY_UNKNOWN)`
could be moved earlier. It doesn't depend on any other
calculations, so failing fast here would avoid unnecessary work.

2. consider using` list_make2(node, format)` instead of `list_make1() + lappend()`.

--
Regards,
Man Zeng
Attachment

pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: Wake up backends immediately when sync standbys decrease
Next
From: Álvaro Herrera
Date:
Subject: Re: Flush some statistics within running transactions