Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: Amul Sul <sulamul(at)gmail(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Vik Fearing <vik(at)postgresfriends(dot)org>, Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions
Date: 2026-03-13 01:00:13
Message-ID: CACJufxGO_qmyGjBvkwhCZzm6bWiqj8iyd1dGbL+_guok6yPMCQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Mar 11, 2026 at 12:22 AM Corey Huinker <corey(dot)huinker(at)gmail(dot)com> wrote:
>
> 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.

We can evaluate CoerceViaIO in an error-safe manner in the HEAD.
However, as discussed in this thread[1], we cannot simply take a FuncExpr
produced by a TYPE CAST, convert it to a CoerceViaIO node, and rely on
CoerceViaIO to do the actual soft-error evaluation.
Therefore to support the CAST(expr AS newtype DEFAULT expr ON CONVERSION ERROR)
syntax, refactoring the existing cast functions to make them error-safe is
really necessary.
Overall I think refactoring the existing cast function (replacing
ereport to ereturn or errsave) should be done first.

I did one more round of comment refactoring and variable renaming.

[1]: https://www.postgresql.org/message-id/CACJufxGw_OY7K3rfG4kDb902O2guhT-wgTjTJQ%3DpWeVWRTHpHQ%40mail.gmail.com

--
jian
https://www.enterprisedb.com/

Attachment Content-Type Size
v19-0009-error-safe-for-casting-bigint-to-other-types-per-pg_cast.patch text/x-patch 3.9 KB
v19-0008-error-safe-for-casting-integer-to-other-types-per-pg_cast.patch text/x-patch 2.9 KB
v19-0007-error-safe-for-casting-macaddr8-to-other-types-per-pg_cast.patch text/x-patch 1.5 KB
v19-0003-error-safe-for-casting-character-to-other-types-per-pg_cast.patch text/x-patch 4.7 KB
v19-0010-error-safe-for-casting-numeric-to-other-types-per-pg_cast.patch text/x-patch 5.2 KB
v19-0006-error-safe-for-casting-inet-to-other-types-per-pg_cast.patch text/x-patch 1.8 KB
v19-0001-error-safe-for-casting-bytea-to-other-types-per-pg_cast.patch text/x-patch 2.1 KB
v19-0002-error-safe-for-casting-bit-varbit-to-other-types-per-pg_cast.patch text/x-patch 2.6 KB
v19-0005-error-safe-for-casting-character-varying-to-other-types-per-pg_c.patch text/x-patch 2.1 KB
v19-0004-error-safe-for-casting-text-to-other-types-per-pg_cast.patch text/x-patch 9.4 KB
v19-0011-error-safe-for-casting-float4-to-other-types-per-pg_cast.patch text/x-patch 3.1 KB
v19-0020-refactor-point_dt.patch text/x-patch 8.6 KB
v19-0023-error-safe-for-user-defined-CREATE-CAST.patch text/x-patch 71.9 KB
v19-0022-CAST-expr-AS-newtype-DEFAULT-expr-ON-CONVERSION-ERROR.patch text/x-patch 116.6 KB
v19-0021-error-safe-for-casting-geometry-data-type.patch text/x-patch 12.3 KB
v19-0018-refactor-float_overflow_error-float_underflow_error-float_zero_d.patch text/x-patch 14.2 KB
v19-0019-introduce-float8-safe-function.patch text/x-patch 3.8 KB
v19-0017-error-safe-for-casting-jsonb-to-other-types-per-pg_cast.patch text/x-patch 6.3 KB
v19-0016-error-safe-for-casting-timestamp-to-other-types-per-pg_cast.patch text/x-patch 3.1 KB
v19-0015-error-safe-for-casting-timestamptz-to-other-types-per-pg_cast.patch text/x-patch 3.6 KB
v19-0012-error-safe-for-casting-float8-to-other-types-per-pg_cast.patch text/x-patch 3.6 KB
v19-0014-error-safe-for-casting-interval-to-other-types-per-pg_cast.patch text/x-patch 2.1 KB
v19-0013-error-safe-for-casting-date-to-other-types-per-pg_cast.patch text/x-patch 2.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2026-03-13 01:02:19 Re: Change initdb default to the builtin collation provider
Previous Message Henson Choi 2026-03-13 00:53:39 Re: Row pattern recognition