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

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Amul Sul <sulamul(at)gmail(dot)com>
Cc: Corey Huinker <corey(dot)huinker(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: 2025-12-02 07:52:57
Message-ID: CACJufxHKoQxo6o3B1R1qqCaYNpntD=esj-hWL5GSCzD1K4FNtg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Dec 1, 2025 at 8:09 PM Amul Sul <sulamul(at)gmail(dot)com> wrote:
>
> Since you declared float8_div_safe() as static inline, I believe it
> wouldn't have any performance degradation since most compilers
> optimize it. Also, I suggest you pass the ErrorSafeContext to
> float_overflow_error(), float_underflow_error(), and
> float_zero_divide_error() so that you can avoid duplicating error
> messages.
>
hi.

First I want to use ereturn, then I found out
float_overflow_error, float_underflow_error, float_zero_divide_error
used both in float4, float8.
ereturn would not be appropriate for both types.
so I choose errsave.
for these 3 functions, now it looks like:

pg_noinline void
float_overflow_error(struct Node *escontext)
{
errsave(escontext,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value out of range: overflow")));
}

pg_noinline void
float_underflow_error(struct Node *escontext)
{
errsave(escontext,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value out of range: underflow")));
}

pg_noinline void
float_zero_divide_error(struct Node *escontext)
{
errsave(escontext,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
}

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

Attachment Content-Type Size
v13-0018-error-safe-for-casting-geometry-data-type.patch text/x-patch 26.9 KB
v13-0020-CAST-expr-AS-newtype-DEFAULT-ON-ERROR.patch text/x-patch 145.5 KB
v13-0019-invent-some-error-safe-functions.patch text/x-patch 12.2 KB
v13-0016-error-safe-for-casting-timestamp-to-other-types-per-pg_cast.patch text/x-patch 3.1 KB
v13-0015-error-safe-for-casting-timestamptz-to-other-types-per-pg_cast.patch text/x-patch 3.6 KB
v13-0017-error-safe-for-casting-jsonb-to-other-types-per-pg_cast.patch text/x-patch 6.3 KB
v13-0013-error-safe-for-casting-date-to-other-types-per-pg_cast.patch text/x-patch 2.2 KB
v13-0014-error-safe-for-casting-interval-to-other-types-per-pg_cast.patch text/x-patch 2.1 KB
v13-0010-error-safe-for-casting-numeric-to-other-types-per-pg_cast.patch text/x-patch 5.2 KB
v13-0011-error-safe-for-casting-float4-to-other-types-per-pg_cast.patch text/x-patch 3.1 KB
v13-0012-error-safe-for-casting-float8-to-other-types-per-pg_cast.patch text/x-patch 3.6 KB
v13-0009-error-safe-for-casting-bigint-to-other-types-per-pg_cast.patch text/x-patch 3.9 KB
v13-0006-error-safe-for-casting-inet-to-other-types-per-pg_cast.patch text/x-patch 1.8 KB
v13-0007-error-safe-for-casting-macaddr8-to-other-types-per-pg_cast.patch text/x-patch 1.5 KB
v13-0008-error-safe-for-casting-integer-to-other-types-per-pg_cast.patch text/x-patch 2.9 KB
v13-0005-error-safe-for-casting-character-varying-to-other-types-per-pg_c.patch text/x-patch 2.1 KB
v13-0003-error-safe-for-casting-character-to-other-types-per-pg_cast.patch text/x-patch 4.6 KB
v13-0004-error-safe-for-casting-character-to-other-types-per-pg_cast.patch text/x-patch 10.2 KB
v13-0002-error-safe-for-casting-bit-varbit-to-other-types-per-pg_cast.patch text/x-patch 2.6 KB
v13-0001-error-safe-for-casting-bytea-to-other-types-per-pg_cast.patch text/x-patch 2.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-12-02 07:54:12 Re: Index functions and INDEX_CREATE_SKIP_BUILD
Previous Message Peter Eisentraut 2025-12-02 07:44:28 Re: Consistently use the XLogRecPtrIsInvalid() macro