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.94.2) (envelope-from ) id 1ugbPn-005HaU-3g for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Jul 2025 03:54:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ugbPl-00DweU-W8 for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Jul 2025 03:54:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ugbPl-00DwdW-MC for pgsql-hackers@lists.postgresql.org; Tue, 29 Jul 2025 03:54:09 +0000 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ugbPi-001PqT-1U for pgsql-hackers@postgresql.org; Tue, 29 Jul 2025 03:54:09 +0000 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-61922872dbdso1232536eaf.3 for ; Mon, 28 Jul 2025 20:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753761245; x=1754366045; darn=postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=tFLRbTeJSfZSCMcRZnHBdkR2BzQF+deG9CT56khdrSg=; b=DA6fzDiE8UrzVyCvnP8QJ4TtaiO78uv6E0L+3doHCs2CjawdZyZ/RdTrnixzRNvYKw Ukls2EdXSZmByiIsyVSHktLWKlhA05uldeL3jdiG3vTjYB+toYEj5Ec1N8AudQ9ojzdw LIKg8GsU74UQYfwL16Q5jvhrcH+giEAcAIO2IOoipFpqsO/ZPoUBuUat202wVfKN4ooN F9QCRuiT9P7lY9XyRXTaiC892Ue2frjZ8xY54C5Z4bipGvt0Pg5A8VkFn8uUnoWHzg6j yMfdZ/pyMAvH+zVrFaCwdhfAI4iJaS6jAaxb5DO+oIuLe3UiOSoXo189c8KrNwtwy+N4 CHJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753761245; x=1754366045; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tFLRbTeJSfZSCMcRZnHBdkR2BzQF+deG9CT56khdrSg=; b=BygCMFGbrt8oKsp5j5LpD93krPJZw/lS959SEREKLJ3i9IXvPXPczHXYKIla2YyDin jJhOA+8oQe1Fe5HyA4F7SK+/ZbRxR1mh8M+CGXYt4r03ye7VO8ehZWuORMV5kWrMFFyL mQYgrVUU46XmiyquBlPCkk9lwVY2c3Uarn5At04xXeV2KVng8+5Nc1MhE8x63meowhrL 9K3yM/8CUpnTWrAlZxtfbr7oqFvCcyDicFnh0RQ9oTFv2FqMaL2LOCyHlfjickbNW8Va h+B43Jo+0UkTqElkrDPdDFPPK4otTIdZzPHdonrIrlbOLSRgqJ+spPeQlKFeB9sZx9RQ 73/Q== X-Forwarded-Encrypted: i=1; AJvYcCWStVSnTvzUId3qTZLt29fzc0KhldOAyLnD35kvb44X3eRLChCrnZt2Znk2RkQ5EpxbfUgzetem4dJNsDhz@postgresql.org X-Gm-Message-State: AOJu0Yzq699VGn26pqeMGmZV0+T+3yZEGIeR6tIT6ldQputiJcUuXI1N E8FeytmTdsyQZrDB3mYU0GIeScryDMf1lh/ms/undexBzDOmx9ltsW/XlQDjnNEujLa5FxMNtbo hkzw5B46jmopC67lGj5bpV/nwrUQt9u0= X-Gm-Gg: ASbGncu48ZrDj6CIp2bhwslur62dwOqU4xyFAERoQ///8RtiLe1hUxDU1Bezy+duydU gvZHhpfkZGDhvQMcWAZ+zeYYBscys5M4IhUJDK7hKGfOT7jI2LsJu0kG5sIfAbUhgeiTCyt1enS Q80YfSFD88Y4bWIGV+UI5W3wjd+Ssxcy1gQ6O/7GjwzeHFyMAoowEjDlcPHS6TA0nMhnOYOkrqI Tw/m/zLaJzfO1eBrA== X-Google-Smtp-Source: AGHT+IHgdxLHZPldW0v46c7dqhPguNioqcmOmB8VODMjnQ+ljfSFBFRElhEFkOhp5B7IHHLN7fgc8j+EqqAoF8UnrqU= X-Received: by 2002:a05:6820:3092:b0:615:d1db:4c86 with SMTP id 006d021491bc7-6190ca1c6e0mr8463807eaf.8.1753761245461; Mon, 28 Jul 2025 20:54:05 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6802:3490:b0:5da:a024:6db9 with HTTP; Mon, 28 Jul 2025 20:54:04 -0700 (PDT) In-Reply-To: References: <4c358bf8-87e8-4760-83d5-a6f9fcd88907@postgresfriends.org> <1b702de4-86b0-4144-a2d0-38266296894f@postgresfriends.org> From: "David G. Johnston" Date: Mon, 28 Jul 2025 20:54:04 -0700 X-Gm-Features: Ac12FXw0g6A-Ya_shIO_Rzx6Qi_rt4szjPu4qE0HNCNkw2X99yWYb9uyXZmjqTM Message-ID: Subject: Re: implement CAST(expr AS type FORMAT 'template') To: jian he Cc: Vik Fearing , PostgreSQL-development Content-Type: multipart/alternative; boundary="0000000000000e8087063b095c6f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000000e8087063b095c6f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Monday, July 28, 2025, jian he wrote: > On Mon, Jul 28, 2025 at 6:47=E2=80=AFPM Vik Fearing > wrote: > > > > > adding these pg_cast entries seems tricky. > > select proname, prosrc, proformat from pg_proc where proformat; > > what do you think? > My first impression of this choice was not good. How about changing the specification for create type. Right now input functions must declare either 1 or 3 arguments. Let=E2=80=99s also allow f= or 2 and 4-argument functions where the 2nd or 4th is where the format is passed. If a data type input function lacks one of those signatures it is a runtime error if a format clause is attached to its cast expression. For output, we go from having zero input arguments to zero or one, with the same resolution behavior. Pass null for the format if the clause is missing or the cast is done via the :: operator, or any other context format is not able to be specified. The slight variation to this would be to specify these 2/4 and 1-arg functions as optional =E2=80=9Cformat_in=E2=80=9D and =E2=80=9Cformat_out= =E2=80=9D optional properties (like typmod_in). The format-aware code can look for these which will end up having the full implementation while the current IO functions would simply stub out calls, passing null as the format. (Or maybe some variation that looks similar to typmod handling=E2=80=A6which I haven=E2=80=99t looke= d at.) David J. --0000000000000e8087063b095c6f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Monday, July 28, 2025, jian he <jian.universality@gmail.com> wrote:
On Mon, Jul 28, 2025 at 6:47=E2=80=AFPM Vik Fearing <vik@postgresfriends.org> wrote= :
>
> > adding these pg_cast entries seems tricky.

select proname, prosrc, proformat from pg_proc where proformat;

what do you think?

My first impression of this choice was not= good.

How about changing the specification for cr= eate type.=C2=A0 Right now input functions must declare either 1 or 3 argum= ents.=C2=A0 Let=E2=80=99s also allow for 2 and 4-argument functions where t= he 2nd or 4th is where the format is passed.=C2=A0 If a data type input fun= ction lacks one of those signatures it is a runtime error if a format claus= e is attached to its cast expression.=C2=A0 For output, we go from having z= ero input arguments to zero or one, with the same resolution behavior.

Pass null for the format if the clause is missing or t= he cast is done via the :: operator, or any other context format is not abl= e to be specified.

The slight variation to this wo= uld be to specify these 2/4 and 1-arg functions as optional =E2=80=9Cformat= _in=E2=80=9D and =E2=80=9Cformat_out=E2=80=9D optional properties (like typ= mod_in).=C2=A0 The format-aware code can look for these which will end up h= aving the full implementation while the current IO functions would simply s= tub out calls, passing null as the format. (Or maybe some variation that lo= oks similar to typmod handling=E2=80=A6which I haven=E2=80=99t looked at.)<= /div>

David J.

--0000000000000e8087063b095c6f--