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

From: Amul Sul <sulamul(at)gmail(dot)com>
To: jian he <jian(dot)universality(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-11-17 13:43:15
Message-ID: CAAJ_b95rrHrY_RJqc=iJQkGrKhUUqTHGO1m3_hJ7A+aG_qxZHQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 11, 2025 at 8:37 AM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> On Thu, Nov 6, 2025 at 6:00 AM Corey Huinker <corey(dot)huinker(at)gmail(dot)com> wrote:
> > [...]
>
> Currently, patches v9-0001 through v9-0018 focus solely on refactoring
> pg_cast.castfunc.

I had a quick look but haven't finished the full review due to lack of
time today. Here are a few initial comments:

v10-0003:

- NO_XML_SUPPORT();
+ errsave(escontext,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("unsupported XML feature"),
+ errdetail("This functionality requires the server to be
built with libxml support."));
return NULL;

Can use ereturn() instead of errsave() followed by return NULL.
--

10-0004:

+/* error safe version of textToQualifiedNameList */
+List *
+textToQualifiedNameListSafe(text *textval, Node *escontext)

If I am not mistaken, it looks like an exact copy of
textToQualifiedNameList(). I think you can simply keep only
textToQualifiedNameListSafe() and call that from
textToQualifiedNameList() with a NULL value for escontext. This way,
all errsave() or ereturn() calls will behave like ereport().

The same logic applies to RangeVarGetRelidExtendedSafe() and
makeRangeVarFromNameListSafe. These can be called from
RangeVarGetRelidExtended() and makeRangeVarFromNameList(),
respectively.
--

+ {
+ errsave(escontext,
+ errcode(ERRCODE_INVALID_NAME),
+ errmsg("invalid name syntax"));
+ return NIL;
+ }

I prefer ereturn() instead of errsave + return.
--

v10-0017

for (i = 0; i < lengthof(messages); i++)
if (messages[i].type == type)
- ereport(ERROR,
+ {
+ errsave(escontext,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg(messages[i].msg, sqltype)));
+ return;
+ }

Here, I think, you can use ereturn() to return void.
--

v10-0018

+ if (unlikely(result == 0.0) && val1 != 0.0 && !isinf(val2))
+ {
+ errsave(escontext,
+ errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("value out of range: underflow"));
+
+ result = 0.0;
+ return result;
+ }

Here, you can use ereturn() to return 0.0. Similar changes are needed
at other places in the same patch.

Regards,
Amul

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo Nagata 2025-11-17 13:52:07 Re: Suggestion to add --continue-client-on-abort option to pgbench
Previous Message Bertrand Drouvot 2025-11-17 13:12:24 Re: Consistently use the XLogRecPtrIsInvalid() macro