Re: implement CAST(expr AS type FORMAT 'template')

From: zengman <zengman(at)halodbtech(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: David G(dot) Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Vik Fearing <vik(at)postgresfriends(dot)org>
Subject: Re: implement CAST(expr AS type FORMAT 'template')
Date: 2026-01-30 16:17:22
Message-ID: tencent_73665D4D79A6E8901E43082F@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
cleanup_suggestions.txt application/octet-stream 3.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2026-01-30 16:18:17 Re: Flush some statistics within running transactions
Previous Message Fujii Masao 2026-01-30 15:28:14 Re: Wake up backends immediately when sync standbys decrease