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 1wevFg-0058LG-0f for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Jul 2026 13:45:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wevFe-00DwGw-34 for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Jul 2026 13:45:18 +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 1wevFe-00DwGo-1k for pgsql-hackers@lists.postgresql.org; Wed, 01 Jul 2026 13:45:18 +0000 Received: from mail-vs1-xe34.google.com ([2607:f8b0:4864:20::e34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wevFc-000000015Rh-2RPs for pgsql-hackers@postgresql.org; Wed, 01 Jul 2026 13:45:17 +0000 Received: by mail-vs1-xe34.google.com with SMTP id ada2fe7eead31-738f3419eedso185617137.3 for ; Wed, 01 Jul 2026 06:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782913516; cv=none; d=google.com; s=arc-20260327; b=E0YsK+x01I4yYsMxU1xI+fcWVVRGo1Fl+r7/nBnOXsKSuYXGW/3RncHbEwj0f+eGU5 1rTJ28Ns86y5/Hm3e/7CZ/gfcJ8LfVpObMy3IP0hjdQ4PYlapQYNg4XX6l0OuTD6SvAS MwPJPK0bg3lmIgRbZbs8OaboYFh0+AV/Qplmd3XV/D1ivovI3GxHQfziKjZ+HDgYMjks AHnEkTeabzIdusDk9LfX0WnjrLQweJgCbNe+7lmLRn/Ww1pUbBoDi2GbcKvNAqU75GEA Rfs3mT4o+4oOnnuIwQ5bpx6ng0lBuMMe6Iw4y9cRwsIq8SYdetsuB7IYtqh4VzsoOsHY luzQ== 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=WgJYgrem1iqK92xFJy9j58kjibQ3eREN8+qqizpOsrw=; fh=qFGI0sisoWYoksFD2Mcxerarqf8ML+FfDUAHkdpgikg=; b=dEp9FK5pPUgUPgmka0HfEyTV8CQrnRPF1EKzVCpGJtGRddgM29SGLuyMjJnLpvxdaM h24S9dUOQUHpgRtL1KQ9nUY6/ZbFa8g1Za15VJ/8es8MIa0A1Nsz+wpgtMDJX1NPcvnU tXxRbLT/PYkVtvdGyHO/cwIUrNBaX+BRPexsLyC3yTWI90vV/UDBOws5kjBPAMHWOB+H 7424dnbsU06021z8BiI581TuBUfqS7pAgTf+9/Wic0QZNb1YCePvsqRKWDTnskM4WiFb v+yqmdor7G15JY8PQ1vuea4LylliTBSRM8sM2s6DM19gLfdrKBrdrGIpG4OgVrs9lJFC k8TA==; 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=1782913516; x=1783518316; 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=WgJYgrem1iqK92xFJy9j58kjibQ3eREN8+qqizpOsrw=; b=O2HWxfYECoBB/hHRv01VcQxn/yDcKqx7SPKZgFGmnGyBlk2MPQNegIwjWlLpgVGG0c UQ2NnVCYqwTS0fhkm7GiJYjLhEBX3rqul1zlExQWzNkp+pAb4ba+bfIh8uLkM/m1McdK UO552KQUmEPyVx9xp7rr7GsdSbFwVUCoDpt39gip0esJjejSe2C6SYn9xmo0TgEjivzH RQbyqivRVGEfdMaOQWvroWYrnVamQ/0S2SUqQJNNUN4TBqpgNIMkvCfGhMZdrIjsZ0tk qjfTf71aI4bh1kPotKYKWm3NB2u4cKw9XIZmvE6sx9qA4BKj9wet+pNQzkVTsDJy2P9V C6eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782913516; x=1783518316; 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=WgJYgrem1iqK92xFJy9j58kjibQ3eREN8+qqizpOsrw=; b=eD4Tg5GgQHp99DJDNNaDh9qGouliJ2/nVDzpFcjuFNJksy2QH/t4BbNkyQ6zZngjzh FUZcve3TRhT3xFM80PxxN9y8ap36v6bdHnyQVdXT9MRLLWLjTtLFZsOjnzwCPRXojyFe +8WarumO71OLPTEZN3SWxhuR0+29KJlwIJhQCI7DEiN0kevpvr5j5cUUKyPPTWyjN16s sNhdlBckoj3efoQlpYykkbV7v0x1HE0eIFqQWAtaCwZOjoH4XVuZYFIcZFUzBCn160so Ptu2PtfeTTglHPI1vZP/uAk5ZF9+setR4CjZZEYYW79iyJv3Si44qgMEKJEIbLqtpJpY k4bA== X-Forwarded-Encrypted: i=1; AHgh+RokRwmWpL7p+FFlkhOA4+8X/lj/M9NeJajUlBBj2d87fuQ9EqNQmH4sEDEmOQPYiWiEqnDBGUcAyb/olwXU@postgresql.org X-Gm-Message-State: AOJu0Ywc+AceNlE5X3wdUBi10o7ryXYf3Q2kwd3/SGQeHm7HEW3R6ttc SUOPbLvNMQX1nvsKCmevtSmQvwHNCnLT5tw3SWcg4b64dpRd5eSvQDWCyDf09HTIc1ox/uCYHyl eDyMFS+lcVX7aWJzCNoICWyGpY6q73o8= X-Gm-Gg: AfdE7ckfUtPEGsg8+/lqOZb833ey22VY4hmRDlRhvT31zrAoESugiKIyKQFN2/w+eMG W4fSKKEBvGyIYkk3y5NMXs5IBNyB8Mor5MqiCU/ofwh9X/4jK/6y+o+DH0Z2ms488Q7ao74EUd0 7vh9IHgokOXcJ/yZOuFNBj0tzidcXwUjtfTvful98YVEXN6KUNYdR06rRd4uWuCd4Vj883OXa8O Pj2Yjiibv9myc6SwCLDVjDLvE5OhSnEr+OGnpm8EyaTShaH6cCwn+N7unRl0ssl1LgSPG2uRcco RaE2rM/arcllLUbRdZbwU523e6RiqL5fBqfqWeIZ7oFv52VjjyBedjKBNGXz7JLamht4WdfECK9 SWAyqQbSZHEwOXtstdL/2vuVR2tFoN4Hc4HA3qUDMawKzxQ2azHCx9PnsyvC+SZ9qmk8+1Xvgqw R2cX+8Lwe0PKH1kX4C3hrxSlbbNw== X-Received: by 2002:a05:6102:3583:b0:631:2cb0:bf8d with SMTP id ada2fe7eead31-73da8516abemr661114137.6.1782913515009; Wed, 01 Jul 2026 06:45:15 -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: jian he Date: Wed, 1 Jul 2026 21:44:37 +0800 X-Gm-Features: AVVi8CfA0ivH4wjl1rfLOnWUe9AE7L92o_-v0ZbA1ElWExM9dXMl5D8WGJ57li0 Message-ID: Subject: Re: implement CAST(expr AS type FORMAT 'template') To: Haibo Yan Cc: Robert Haas , Corey Huinker , Zsolt Parragi , Vik Fearing , "David G. Johnston" , 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 1:39=E2=80=AFAM Haibo Yan wr= ote: > > Thanks for looking at the patches. > I liked your suggestion to call these =E2=80=9Cformat casts=E2=80=9D rath= er than > =E2=80=9Cformatters=E2=80=9D, so I changed the series in that direction. = The DDL is > now: > ------------------------------------------------------ > CREATE FORMAT CAST (...) > DROP FORMAT CAST (...) > ------------------------------------------------------ > rather than CREATE/DROP FORMATTER, so the patch no longer adds > FORMATTER as a keyword. > I also renamed the related catalog and node names, so this now uses > pg_format_cast and CoerceViaFormatCast. The > pg_dump/object-address/comment/extension code and the regression tests > have been updated to use the new terminology as well. > The rest of the design is the same as before: format casts are still > catalog-driven, and both built-in and user-defined cases go through > the same lookup path. > In an earlier thread [1], [2], I proposed introducing: CREATE CAST (source_type AS target_type) WITH [SAFE] FUNCTION function_name [ (argument_type [, ...]) ] That drew some pushback over non-standard conformance. Here, we are introducing CREATE FORMAT CAST (source_type AS target_type) WITH FUNCTION function_name [ (argument_type [, ...]) ] This syntax is quite close to CREATE CAST. per https://www.postgresql.org/docs/devel/sql-createcast.html CREATE FORMAT CAST would be an extension to the standard, though we already have non-standard precedent: AS IMPLICIT. Before proceeding, do we need to reach consensus on the syntax itself? Does the following alternative syntax make sense for CAST FORMAT? CREATE CAST (source_type AS target_type) WITH FUNCTION function_name [ (argument_type [, ...]) ] AS FORMAT ---------------------------------------------------------------------------= ------------- As I mentioned previously [3], there's an open question around this case: CAST('{2022-01-01, 2022-21-01}' AS DATE[] FORMAT 'YYYY-DD-MM'); does this mean the format template ('YYYY-DD-MM') should be applied to each element (2022-01-01, 2022-21-01) individually via the cast format function? This matters because it affects check_format_cast_function's handling of argument_type. According to create_format_cast.sgml, the format function sh= ould take exactly two arguments, with the last one being text. If array types ar= e to be supported, then argument_type would need to become either (source_type, format_text) or (source_type, oid, int, format_text). Sure, we can support formatted casts for array types later, but we still ne= ed to think through the array-type formatting design now, so that the cast format function's argument types won't need to change later to accommodate arrays. [1]: https://www.postgresql.org/message-id/5ae9578e-f25e-49c5-97ab-ad27bc20= 50b5%40eisentraut.org [2]: https://www.postgresql.org/message-id/attachment/192833/v23-0023-error= -safe-for-user-defined-CREATE-CAST.patch [3]: https://www.postgresql.org/message-id/CACJufxGVuCM4XFGqaqiV-VOEiqMtCZ3= %2BT-%2BSrG-y6kqdLo1ZqA%40mail.gmail.com -- jian https://www.enterprisedb.com/