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 1vg9AB-008jFm-2x for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 22:16:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vg9AB-00DG1G-0S for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 22:16:27 +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 1vg9AA-00DG0l-2K for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 22:16:27 +0000 Received: from mail-oa1-x34.google.com ([2001:4860:4864:20::34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vg9A8-000SVx-1b for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 22:16:26 +0000 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-3ffc3d389a8so185260fac.1 for ; Wed, 14 Jan 2026 14:16:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768428984; x=1769033784; 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=6g1aIAg5yL+S4UUf4vbgnATLabWn0+ZdFO3xo5g7B5o=; b=afCm6Nw44perBZYpXmiSPb0CQRIAgAdgfgG7egVQiGhUrzHg8r6l62ZOw5KhLinAeK vFjKk0s97bWoxNl42v85mhGfftm5sSYgNVYSD6y7A8IU5I71pFOs1I0wrChYZGt5IBYe 5xbwlNVLNcgT2Z1okd/2R2bRYiWG+SyLdaMwLYvhVkJUpVuy0C/F4jV1RwpF52ECtbfn 8IWzOXLFjYXyjhhXcZWpLFJ8ZqgE+9vzkg0F4/r1uOL4zipUlyy/KTovX0ZOyR8370yl 96oH/8QJkQBjb8HVjX5+GwOEN120xvaHSERtmL5jkN0uU589QoVkeUf5B0pFu3FO56TR 4CFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768428984; x=1769033784; 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=6g1aIAg5yL+S4UUf4vbgnATLabWn0+ZdFO3xo5g7B5o=; b=qf4JeTdDPvmYm8uJFlPKnp+RBXBuUXnz2hVNJEqtPaAURcMa+EtKE+YRNUi6RStK2o zzvz9md+8id3qb5pjF+OERxGVebZlz78jQdbdEowA77bB8afCgc+mwzb+Xm9wdNMGgc9 jXaiCpObi8QT1LkTQu+plbqJjfr5/kWWTcG8lOMjCEUXkRGUco42pTJL7qTYF0TTT+ky nA+9pxQCW9nOI2FL72s5z72AdETlKzcvz9SeqK8PjNPdwE4VoDllfYpOZzeRJX+QM1Ap d5XDw6eWH0t3Db9EgRGvmK9UM3w19QGflDFlL41gUtu8zey3rtQkDn5djKFqaL+qF5p4 Fmnw== X-Forwarded-Encrypted: i=1; AJvYcCViafj0CcunOHbSArkomX/CwWyZnOHxIUGETKGXeqtoADGoXZDetNUFNqhk5+npZgbC4433VQnPHHjDarno@lists.postgresql.org X-Gm-Message-State: AOJu0YwKP/OCyGPW2CPJG2MuzfFkHt17VhYFBhqkzvGehjBFPWOUIIey q/ftcAHTUpfn4cbc6FhG/5SyfTUO43SDJOjICjLxE+kI/lMsw8KJUek8qMxZzZTNRQHnkIN5++O bcZGEID6TzzHXfcuJg9lFs6MM9vp3Ass= X-Gm-Gg: AY/fxX4ZQIqN/nDypf8EU53Ayg1oi8IRlN6lAKXjgUb46GvL5cqWo/svZBtxIYsmBkj WUZtvJ77Gzpa55xqvTfshO5gmM7Z/Uz1KbMdsMWc7hqbeiOJC+xXx17njD6l/Pp1FIz29r0FoCT NeIwdZ5/vA1yqUim7rHLyajH74D9BDlo4D9vTZMTmkoxFApua2GZgAIhvLdEElw4rBhiuQP6LS9 3KOnM+IM/hICCC6cwSmyVP6/yK53sHAlVwwE8ncOYix4oG3v2PdLnAX67NqoBloZrJRRGMRu3QD Y52Vm/ztVjavjVKjBaKZZYvZg9G3KAKPIw66qg== X-Received: by 2002:a05:6820:861a:b0:660:fbc0:fc9c with SMTP id 006d021491bc7-66100732493mr1923567eaf.46.1768428984681; Wed, 14 Jan 2026 14:16:24 -0800 (PST) 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: Wed, 14 Jan 2026 17:16:12 -0500 X-Gm-Features: AZwV_QiQ4Oswf-wt7yKvFZGkT3FHgljsQIFwD-SZjOMguAPm9WovmPREKmHP1Oc 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="000000000000714df1064860750a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000714df1064860750a Content-Type: text/plain; charset="UTF-8" > > > + /* > > + * 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 expression 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. --000000000000714df1064860750a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> +=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.
--000000000000714df1064860750a--