public inbox for [email protected]  
help / color / mirror / Atom feed
From: jian he <[email protected]>
To: Haibo Yan <[email protected]>
Cc: David G. Johnston <[email protected]>
Cc: Robert Haas <[email protected]>
Cc: Corey Huinker <[email protected]>
Cc: Zsolt Parragi <[email protected]>
Cc: Vik Fearing <[email protected]>
Cc: PostgreSQL-development <[email protected]>
Subject: Re: implement CAST(expr AS type FORMAT 'template')
Date: Thu, 2 Jul 2026 11:23:10 +0800
Message-ID: <CACJufxE=UyyPDyv1LhiKFUU7VGceH_9EwfiFXzcAeFY7R8gZeg@mail.gmail.com> (raw)
In-Reply-To: <CABXr29Ed4NW4Uk=TBTBwWpJT1YbwYifHSQ7Ny_=o95YR=-c7RQ@mail.gmail.com>
References: <CACJufxGqm7cYQ5C65Eoh1z-f+aMdhv9_7V=NoLH_p6uuyesi6A@mail.gmail.com>
	<[email protected]>
	<CACJufxF4OW=x2rCwa+ZmcgopDwGKDXha09qTfTpCj3QSTG6Y9Q@mail.gmail.com>
	<[email protected]>
	<CACJufxEH-8UPdbPoUoqNRaiOePw+s2W2DG4OpXtoSYDaW30oAg@mail.gmail.com>
	<CAKFQuwZXYxPw4wofq+zZ5D7nH0sHDBwr--qku9jWYv7dS+P8RQ@mail.gmail.com>
	<CACJufxGTeSnHn7w8r-qoQrqwCFQSC+CbiEthzpHKUd+bPr_0mA@mail.gmail.com>
	<[email protected]>
	<CACJufxGbsc3g6RZf0rZpKYxffK6vGkc_OsTmX54uS0kFcVBtvA@mail.gmail.com>
	<CAKFQuwaG00tsXc2oSQwjdSnPQ=JuH+T8Oeejb3sO5TeqUHsfUQ@mail.gmail.com>
	<CADkLM=cvhJBrCj3GV+jXfpb5+U1Z33nsvCXo-=ZkDyaSPbS-1g@mail.gmail.com>
	<CAKFQuwYrwM64YnvZ5aL1DEWG50uW-1SrXesSKkmvpxXXrxTW-g@mail.gmail.com>
	<[email protected]>
	<CACJufxH+soqLj_AuMQj-_jxunVQKX-HBQA_3_3vmV1jTRyZ1hA@mail.gmail.com>
	<CACJufxGhOOYnPtmsuVocXVNyx2gB3K68ze67CM4LUqQeW--S8g@mail.gmail.com>
	<CAN4CZFNnqWbyk3UNr3XAwtKJooH8LnbDUg-f2JD9z_rG=feT7w@mail.gmail.com>
	<CACJufxFVMYuVz63DteEjbMdvx2neoYcwSRb5vhO-03Tzx=B8Jw@mail.gmail.com>
	<CAN4CZFNeCfLzt5g90vf_Dw5BKW2u-QhVKo369XbO-vXYq4ci5g@mail.gmail.com>
	<CACJufxH4ELUjdGNi7vkHEA6L=G0SfE5abnFs5vjvEm3G-Jqsbw@mail.gmail.com>
	<CADkLM=dGxwVCp3y8=LU+8hQUPw61JELx2jh02i729YCex8UqWg@mail.gmail.com>
	<CA+TgmoaUzwAxa_qHSp9ybCkAhMjQRDuEAZW2BrSb1DTPiz4ZzA@mail.gmail.com>
	<CABXr29FyPC7terFF7E+r462BEHhYgv06oUVoBrhkH7xhshuE6A@mail.gmail.com>
	<CA+TgmoYW4_Ze_iT-o64VuFGqpm48hh=4dyZJwqiWfRPDTW+L+g@mail.gmail.com>
	<CABXr29HF+AHV0FNxQfHyN-ByW6-3+pTBe5Pxm23wRpBYOmfohA@mail.gmail.com>
	<CACJufxFM1cq+wj8ydmsPAYEh63g5rP2tdn+y3QOUrhaA1a+Sgg@mail.gmail.com>
	<CABXr29FJ94+DNwktmCjt=WNLmYzUAUREqr-P01CuiUksC8Y0SA@mail.gmail.com>
	<CAKFQuwbOgm=-Q-J1pRR30Xcg-RcCmSOJ5RFduoQgHNZ08OvxnQ@mail.gmail.com>
	<CABXr29Ed4NW4Uk=TBTBwWpJT1YbwYifHSQ7Ny_=o95YR=-c7RQ@mail.gmail.com>

On Thu, Jul 2, 2026 at 8:01 AM Haibo Yan <[email protected]> wrote:
>
> CAST('{2025T01-01,2026T02-02}' AS date[] FORMAT 'YYYY"T"MM-DD')
>
> could reasonably mean: parse the array structure as usual, and apply the
> formatted text -> date conversion to each element.
>
> The current patch does not implement that.  It does an exact source/target
> lookup in pg_format_cast, so an array target would currently require a format
> cast for the array type itself.  But I agree that this may not be the behavior
> users would expect, especially given the existing array coercion behavior.
>
> If we decide that element-wise array formatting is required, one possible
> implementation would be to keep the scalar format-cast function signature as
>
> function(source_element_type, text) returns target_element_type
>
> and add a format-aware path in the array coercion logic.  The array expression
> would iterate over elements and pass the same FORMAT expression to the scalar
> format cast.  In that design, the array container itself would not need a
> separate format-cast entry.
>

In some cases, ArrayCoerceExpr might help, but not here.

CAST('{2025T01-01,2026T02-02}'::TEXT AS date[] FORMAT 'YYYY"T"MM-DD')

parse the array structure as usual, which array_in do all the heavy work.
arrray_in(cstring, oid, integer).
But once array_in is finished, we already get a date[] datum, then
FORMAT is no longer needed.
I also mentioned [1] that add a text argument to array_in is not possible.

I guess not supporting arrays in the initial patch should be fine,
since not all CASTs support CAST FORMAT.
That raises another question: for user-defined CREATE FORMAT CAST,
should we ban anyarray as the first argument type?
If we don't, will it conflict with array support once we implement it later?

[1]: https://www.postgresql.org/message-id/CACJufxGVuCM4XFGqaqiV-VOEiqMtCZ3%2BT-%2BSrG-y6kqdLo1ZqA%40mail...






view thread (56+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: implement CAST(expr AS type FORMAT 'template')
  In-Reply-To: <CACJufxE=UyyPDyv1LhiKFUU7VGceH_9EwfiFXzcAeFY7R8gZeg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox