Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wf8pG-005I3D-2y for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jul 2026 04:14:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wf8pF-00H5GB-0G for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jul 2026 04:14:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wf8pE-00H5G3-2A for pgsql-hackers@lists.postgresql.org; Thu, 02 Jul 2026 04:14:56 +0000 Received: from mail-yx1-xb132.google.com ([2607:f8b0:4864:20::b132]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wf8pC-00000001BC2-2q9q for pgsql-hackers@postgresql.org; Thu, 02 Jul 2026 04:14:55 +0000 Received: by mail-yx1-xb132.google.com with SMTP id 956f58d0204a3-664ae993e4bso356606d50.0 for ; Wed, 01 Jul 2026 21:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782965694; cv=none; d=google.com; s=arc-20260327; b=KNxibdC79DXWdB02q04FeZdGfSvVaedsw43bwCvxOoPfC6Z8jdgrQuHeSJVDYOmX61 O9QBNgCWizzh0lJHJHonjGTXEwe9E9KO0h6eCzWzuKDJ00J2gUhxZeVtCdgyn/g+88L5 Lkd159crH6Gr9fK92uK7aFZDEFfg1Zbg4nHMBq+H5DnxmgBar6D+WgH+b0geloZOsLxl uTsDkcS9Qfv/wqappBrzm9xkQYiEWqVEynrzxXVeOOPmAqR+mLgaV5k24HayH0T4Fpv0 reR4SgMlhXSLQJvpSeDmoRAUQhFIlgTZAoFEaHb3NeNqPK1d8jpj94qZcxeL+uwFeWth gKIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oUWMbqjTAF+JW5Tf/MEY2v2kaYqKZ9JJVkTN9bH19XA=; fh=A4cGDyq/9C6C7zlz4VjazOdRc4k4zo219oKPhm/ppQA=; b=a1pPPiIM4YzTN6DTc7XAmz3ZmfDSQPI8yvn5LCfmEV/au8OyfechrNaL4Odv6og/Si g4tveWYUy90Tc5gBPrGM12HLiAMcv7K3RpGEfFGPhT/AcrB/syjW+7ZEfO1ktHKH6X4X R+bLq5l6LOfxskfkoCnO/T9jzKKhOHizjAiB6wzLB0vg0HDj2wCC54D8SMtt8m1fGtYc ZEnFycD7xIlsVT3qNuNKlNy6zRdnShR7dzfDTGeJF/wX0J+E3v+J8kmOXX+DxxAraX3q 7qWA1sJ4h33aUFQah4TMohjLrncb4DAbYH2sCJ2HxfT2kyhVL3NNRefbPFEgPVVIrQ8/ PWzQ==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782965694; x=1783570494; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=oUWMbqjTAF+JW5Tf/MEY2v2kaYqKZ9JJVkTN9bH19XA=; b=DjfgiYZ5MNuQOWXb80X4XJJtzbMGDS8Ypamv0nkzasrViNkGaXeYMOVJspDEf9J0N4 9XzjaqvnSM8VQ8LGeEr9F6GYBnjsggtq+DuiUNO+Y2B7J2O/ZoJTECZDR6JDckjvbRM6 cBp3tyQhVlfg+Fvu4W3xqerZafpxlckl13bFR7xIhWmgb6QDDePHmwrV5CvFM0QdTPZN C2AyOzvjkHt8HWN/H3PvksJGjiydWegYbS0hn4bQg6nQQbDHHIC2j2Z52Wmq5PCtRwu/ G7kskFiJiC5Sbb8g/hUTI3/hptzk6M0WiKN608ZER9H+gH5DzyGrA/+qBHDnJ4RZg9BB N1MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782965694; x=1783570494; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oUWMbqjTAF+JW5Tf/MEY2v2kaYqKZ9JJVkTN9bH19XA=; b=boITrnM6wrY7p5oN3xC/BAlSc/umSMIqGwBmJD82BqeGXSjis0W+1k8M9etVLKOJN9 iwCDmVwJwrD2/qn9yvDA5VUjwUXmHkva2DYIXyixNMOorRagDvHNUYtjLwaVzOfKCVyc 5LDKxFKiaPGDn838yXYQ0t6GmlNLasFWLCZBSSp7mwCgJIT3dv8WO9oOl33+L99Cy6VX /eE6X6L/q3LsSHCAEtTYnC7eeHEOdjDvS/sJsVIvdvn5N8ubK2GuEV67HI4A8F+KySvH SWeCM7jpX9op4lQpG+7TJdbHhqaxInsUw/0JHRLLtgqanFhrahQZHl+XEk/R3nvkvI1s GCMQ== X-Forwarded-Encrypted: i=1; AHgh+RrAM2scjFCJTNUpiPJQFZ64IoB7p8zmhYO6v4cwj290t9weFvY97N92WgN3+SE/Yh2gec7jbxefD2kFPT2s@postgresql.org X-Gm-Message-State: AOJu0YyrFsnmHy/3TZWa3iMrKKpIOiTnT0nkdK4qxQN17EMYtMyBBAk3 Nua6kDGBeARMeDNe1mV8hyO+GIWD7sXaQauyumzcBJV6UGH7dwPrlezAaTn8M7YYYyIR9vYGLsS /KNwsQ4ET37Rca72h4BSD6ktaUU7RODc= X-Gm-Gg: AfdE7clllDZoOO71HCr6D49MuXpH0+5rEc3Vlo8aWTJqRYirnBMzQI1Wj9DDY0ytJ2q oaNcVzYXoK8DRvc+6M9nriCfV5LbOY+kAWMqLZa9bFhc2hT50I/QKrE8YOMXQ8kMzMk68rJ6xpf /HKvDWYfoCzP4rq1XEwsONbr+Vhp8APMCUcBs5bMfQ950aiXhBOYutCJOkQOgB0+7C+AC0R8sxv GIwntf2nh4R5nNzvJpcwZgLa7XSpY9ud0UhE1tqM9oMJK7fWa7o1lpJMlIWLHy6iPQzc4nbTqjE cwzIlt7ChmvINrK2jHUmzKIGdpO0TjlSF8Y= X-Received: by 2002:a05:690e:e8a:b0:660:6e93:1958 with SMTP id 956f58d0204a3-665209515ccmr3994350d50.0.1782965693777; Wed, 01 Jul 2026 21:14:53 -0700 (PDT) MIME-Version: 1.0 References: <4c358bf8-87e8-4760-83d5-a6f9fcd88907@postgresfriends.org> <1b702de4-86b0-4144-a2d0-38266296894f@postgresfriends.org> <82b4223e-84d4-432d-8167-dd698ce489f5@postgresfriends.org> In-Reply-To: From: Haibo Yan Date: Wed, 1 Jul 2026 21:14:42 -0700 X-Gm-Features: AVVi8CfwBjB-waY_nPByBfVKo_h159mhsmXDpo3vGhACpC2165BdXMkfbFKpHwY Message-ID: Subject: Re: implement CAST(expr AS type FORMAT 'template') To: jian he Cc: "David G. Johnston" , Robert Haas , Corey Huinker , Zsolt Parragi , Vik Fearing , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 1, 2026 at 8:23=E2=80=AFPM jian he wrote: > > On Thu, Jul 2, 2026 at 8:01=E2=80=AFAM Haibo Yan = wrote: > > > > CAST('{2025T01-01,2026T02-02}' AS date[] FORMAT 'YYYY"T"MM-DD') > > > > could reasonably mean: parse the array structure as usual, and apply th= e > > formatted text -> date conversion to each element. > > > > The current patch does not implement that. It does an exact source/tar= get > > 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 b= ehavior > > users would expect, especially given the existing array coercion behavi= or. > > > > If we decide that element-wise array formatting is required, one possib= le > > implementation would be to keep the scalar format-cast function signatu= re as > > > > function(source_element_type, text) returns target_element_type > > > > and add a format-aware path in the array coercion logic. The array exp= ression > > 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= . Thanks, I agree that ArrayCoerceExpr is not enough for that case. the normal array input path would already have to parse the elements as dat= es while constructing the date[] value, so the FORMAT clause cannot simply be applied after array_in has returned. > > I guess not supporting arrays in the initial patch should be fine, > since not all CASTs support CAST FORMAT. I think that means array support needs a separate design. For the initial patch, it seems better not to support formatted casts involving array types= at all. > That raises another question: for user-defined CREATE FORMAT CAST, > should we ban anyarray as the first argument type? yes, I think polymorphic pseudo-types should becrejected. The current patc= h already rejects pseudo-types, so anyarray should not be accepted. But to avoid future ambiguity, I think we should also reject concrete array source= or target types for now. Otherwise, a future element-wise array design would have to choose between = an exact array-level format cast and an element-wise scalar format cast. I do= n=E2=80=99t think we want both meanings. If array support is added later, my preferenc= e would be for it to mean element-wise application of a scalar format cast, w= ith the normal array machinery still handling the array container syntax. > If we don't, will it conflict with array support once we implement it lat= er? So the initial rule could simply be: no polymorphic pseudo-types, and no ar= ray source or target types for `CREATE FORMAT CAST`. If people agree, I can up= date the patch and documentation that way. > > [1]: https://www.postgresql.org/message-id/CACJufxGVuCM4XFGqaqiV-VOEiqMtC= Z3%2BT-%2BSrG-y6kqdLo1ZqA%40mail.gmail.com Regards, Haibo