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 1vzzr1-001Vw8-2d for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2026 16:22:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzzr0-004VvV-0H for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2026 16:22:42 +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.96) (envelope-from ) id 1vzzqz-004VvN-2W for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2026 16:22:42 +0000 Received: from mail-dl1-x1233.google.com ([2607:f8b0:4864:20::1233]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzzqy-00000001zic-0AV0 for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2026 16:22:42 +0000 Received: by mail-dl1-x1233.google.com with SMTP id a92af1059eb24-128e4d0cc48so414294c88.1 for ; Tue, 10 Mar 2026 09:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773159758; cv=none; d=google.com; s=arc-20240605; b=B/i7ix1k7eVJj+/o3yUDmIlT53QY+cXuGfWAaSngPsNJZ56gEEaX6JzoLgd0zxr6tC HSW0vtnvYq3MnhNttBVPC6zoKY/P161xIHnis+LewEB5GpclHRnx/XyCT2NvueKjpf/N XKU93/GYRdSVQDobIszgBX4QQnhX6NtiK+U1CHIHUdJZD2SmYKUhasXaGZmik4yCvJwn Eg920Ar0fyYTf0zYc7wqkaHVh4HA1hgpocGHyGHcODmxh+VdxcyAWprgc0/OUjLXJ2ZJ X21UUZLIwjVjg3bCL2YyBA8hYR4gAs5nsLvoOpZ5hJ28G/IrfSbpn88kkKhLxVzwC7B6 x5eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=XlAOMi14sQc2Qhr/FMOxj8gnFFoUhR4ZfSLzxQXj328=; fh=IPW6ZXi/UHpPzmMoYC/PzECgL2An8UpKz5qosBj4o4I=; b=AyENPHrKbAj2mlmAy7OpiXXYSuyDmVs9obkTcWOYJtnVC/qbTM5/Z5nxl+aXYUTcvs 6XZpwe+DekTQB3FbM7dEzmZtDTz+9Bg4gAcxXnTjXiywbVS9nFggaDAqn9blkAg/KRfv gULPAHmc6K6rZKLvvs2+SKPkmrXSY47dpzdl99mbc5ecTb6JIvZ5speTbQ2yoxqk7xAJ DRdfJlwxYkEAi41Gui/JO6qMKCuw3/dGmhJrDn1OhW+JTIOGyDqZRvjXu15lX5a0Q4XS 5oWCtI43QtnaFLl4MCozIxfeb6kQD3zPWA5OSiHWowHv81Oxm7XL4AJWXKpf5+kLzMTk 64AA==; darn=lists.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=20230601; t=1773159758; x=1773764558; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=XlAOMi14sQc2Qhr/FMOxj8gnFFoUhR4ZfSLzxQXj328=; b=RMAaudNlEuva08spG5IErrQ6MCvpPRs+WxfxiPbdaQtMZEUKcO2sKSDL43rxDZXqOH BMEA6jjMm7eyWYecEKNg2ZdtTfgo6kjiIfFkTvGYXmtWqtguBjdvRGIOc/ShRQ6xwfB4 JuKBsMBDolePw8PVFNcRhYgB2WC8c/nQaOn6EBgJKlFN6UENz+d28a/E9X74Y3EiF3mm c+gckNwBKIMHRhuczldN0GrXQyq93v/hu/zc03csmbb1OisXdHzEr2qo0u+pBwNJieBD OFIcZRS8VADIepFA89uN/jAJhmF2sNuQ/lYxUBgQQ0wWSGWXP36tgVJIEUqPr0TOTfuT fosQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773159758; x=1773764558; h=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=XlAOMi14sQc2Qhr/FMOxj8gnFFoUhR4ZfSLzxQXj328=; b=I6XBbUxXcMACPJAl87KhTHFSV7hW1gwcwEFy+xNcl3A1U4k8Ne89ZEsS+VLIDv0A+x 0zPCxDFvXHrzYIu9IumjY4mLA9cIm++kTBqfQjGw7j6PaYzvavcNpzbDm7ShMH2De78S kfRGHxvFSN2UJl+ubQtICucfHEMwoK2Te2oZCooWsNUfB2Fborx2Qured9wzju3PK0Yw vYOOntV2TWUAgN56qc+BGKapK7CiVebrf2cc6ghVkimgCTlNEznMFVMrmFzSl16w/oYl KC2ggXwVdl0Pfq2xTwwtoxjYIF36SF3Fwkl+Y3IrHthNevvgjGXK11UpVBXs2l1ZSkJ5 SleQ== X-Forwarded-Encrypted: i=1; AJvYcCU3MeVsXU1FYj+O1O4cMzmvOccriBnKivznOUQSmm/2gg+uW6QB9bPIejs0JLnYRqh/yD7xM59Cl3ud3iTG@lists.postgresql.org X-Gm-Message-State: AOJu0Yzul7QcdwVzojz6w9fX0kypiK+6uIybvw28BuAtf0EU5FAGApZj 23W5cVohTw4ykHL8FYkHSo9DMYsVSsdX2426vdUol0FrY1cCyE78rZ4oJ1tnziqijqNjRcIF+07 m5UlaO1Jn8z8GAutsKoimGPDN+lgUxiE= X-Gm-Gg: ATEYQzwna+OjmXKbK5vDp/Sk1TNH03yXbuuVkbCpIW5DwS4to/OKvEyt1w0EqR0tn37 3D+SWenT+4MkmEd39xCJVFnaXJLldLPIfj7L27tXaH8xOkdNwMWyIpnONiZQFZHfTpACF52z2xP BtOO3ndUZuEsJlxmLg09ITVz4+UBQeQs6jCcKOb3CWDRh9lMmNmvscYJ2JzxuBtqzQKC9N5oSbE V6qLz7ltQ9+K4hoPHu/es3iRjS1TdbjMVjIA3D9SjYC430eAOd5X+reNJnDI9JSCi3EjsW9dm0t 6oO6VXfbUi65q5RyUvTnDYxAR4CY4nPwhw2WLjvMjQAKSvR5LSjl39nWG0TB/Qvk57ru7zl5jy5 +aari1u4vDwxaKCZvbLrMAvhi7n3ChjW4PZI= X-Received: by 2002:a05:7022:e0b:b0:123:345b:ba05 with SMTP id a92af1059eb24-128c2e8c5a8mr6452103c88.22.1773159758136; Tue, 10 Mar 2026 09:22:38 -0700 (PDT) MIME-Version: 1.0 References: <04afcd1f-ed7d-4c0a-add1-50e3719ccbf9@postgresfriends.org> <762ae707-7fdc-43d8-a77a-3a10d12ce21d@postgresfriends.org> In-Reply-To: From: Corey Huinker Date: Tue, 10 Mar 2026 12:22:25 -0400 X-Gm-Features: AaiRm53ZTl-NLZrwhnKxBOTBV1eTFtFY3hobgAXs8kO2V_3hh1HiVqn2dr1cIMg Message-ID: Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions To: jian he Cc: Amul Sul , Kirill Reshke , Vik Fearing , Isaac Morland , pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000838ae8064cadedee" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000838ae8064cadedee Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 14, 2026 at 5:16=E2=80=AFPM Corey Huinker wrote: > > + /* >> > + * Here, we cannot deparsing cast_expr directly, since >> > + * transformTypeSafeCast may have folded it into a >> simple >> > + * constant or NULL. Instead, we use source_expr and >> > + * default_expr to reconstruct the CAST DEFAULT clause= . >> > + */ >> > >> > I am wondering how other places handle expression deparsing; do they >> > hold the original expression along with the transformed expression? >> > > In my initial implementation of this, I modified CoalesceExpr to ensure > that the default clause was evaluated if and only if the initial expressi= on > failed. > > > >> rebased, many variable names have been renamed, comments adjusted. > > > The new SAFE option on user defined cast functions looks good to me. > > I am concerned that adding _safe overhead to all cast functions will be > received poorly, but if it is poorly received then reverting isn't that > hard. > > I'm going to re-review the whole patch set, but I wanted to say that I > like the main points of the changes so far. > I picked this back up again, pondered adding the IS CASTABLE AS syntax to the patch, but ultimately decided that it should be a separate patch. While I still think the patch order is a bit backwards [1], the order chosen does have a sense to it, and whether or not that is the right order is up to the committer. Please post a rebase so I can mark it as ready for committer. [1] I would have preferred adding the CAST functionality first, then switching over each datatype one-by-one, thus demonstrating that non-safe datatypes can co-exist with this new functionality. But that's just my personal preference. --000000000000838ae8064cadedee Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Jan 14, 2026 at 5:16=E2=80=AFPM Corey= Huinker <corey.huinker@gmail= .com> wrote:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/*
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * Here, we ca= nnot deparsing cast_expr directly, since
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * transformTy= peSafeCast may have folded it into a simple
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * constant or= NULL. Instead, we use source_expr and
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * default_exp= r to reconstruct the CAST DEFAULT clause.
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 */
>
> I am wondering how other places handle expression deparsing; do they > hold the original expression along with the transformed expression?

In my initial implementation of this, I m= odified CoalesceExpr to ensure that the default clause was evaluated if and= only if the initial expression failed.

=C2=A0
rebased, many variable names have been renamed, comments adjusted.

The new SAFE option on user defined cast functions = looks good to me.

I am concerned that adding _safe overhead to all c= ast functions will be received poorly, but if it is poorly received then re= verting isn't that hard.

I'm going to re-r= eview the whole patch set, but I wanted to say that I like the main points = of the changes so far.

I = picked this back up again, pondered adding the IS CASTABLE AS syntax to the= patch, but ultimately decided that it should be a separate patch.

<= /div>
While I still think the patch order is a bit backwards [1], the o= rder chosen does have a sense to it, and whether or not that is the right o= rder is up to the committer. Please post a rebase so I can mark it as ready= for committer.


[1] I would have preferred adding the= CAST functionality first, then switching over each datatype one-by-one, th= us demonstrating that non-safe datatypes can co-exist with this new functio= nality. But that's just my personal preference.
--000000000000838ae8064cadedee--