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-24 03:38:08
Message-ID: CAAJ_b97SC8LknASnDASqV951pBHLpxwUmE7wPQKAcWyzuDujdA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 21, 2025 at 2:11 PM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> On Mon, Nov 17, 2025 at 9:43 PM Amul Sul <sulamul(at)gmail(dot)com> wrote:
> >
> > 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.
> > --
> >
>
> hi.
>
> List *
> textToQualifiedNameList(text *textval)
> {
> List *namelist;
> rawname = text_to_cstring(textval);
> if (!SplitIdentifierString(rawname, '.', &namelist))
> ereport(ERROR,
> (errcode(ERRCODE_INVALID_NAME),
> errmsg("invalid name syntax")));
> }
>
> I don’t see any way to pass the escontext (ErrorSaveContext) without changing
> the textToQualifiedNameList function signature.
>
> There are around 30 occurrences of textToQualifiedNameList.
> changing the function textToQualifiedNameList signature is invasive,
> so I tend to avoid it.
> I think it's easier to just duplicate textToQualifiedNameList
> than changing the function textToQualifiedNameList signature.
>
> Am I missing something?
>

The change I was suggesting will be as below:

--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -2684,6 +2684,13 @@ name_text(PG_FUNCTION_ARGS)
*/
List *
textToQualifiedNameList(text *textval)
+{
+ textToQualifiedNameListSafe(textval, NULL);
+}
+
+/* error safe version of textToQualifiedNameList */
+List *
+textToQualifiedNameListSafe(text *textval, Node *escontext)
{
char *rawname;
List *result = NIL;

We must try to avoid duplication whenever possible, as any bug fixes
or enhancements would need to be copied to multiple places, which is
often overlooked.

Regards,
Amul

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2025-11-24 03:51:58 Re: Allow GUC settings in CREATE SUBSCRIPTION CONNECTION to take effect
Previous Message Chao Li 2025-11-24 03:29:53 Re: generic plans and "initial" pruning