Re: Use IsA() macro instead of nodeTag comparison

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Shinya Kato <shinya11(dot)kato(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Use IsA() macro instead of nodeTag comparison
Date: 2026-01-09 05:47:33
Message-ID: aWCWdY5hhTP4voAg@ip-10-97-1-34.eu-west-3.compute.internal
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Fri, Jan 09, 2026 at 08:56:00AM +0800, Chao Li wrote:
>
>
> > On Jan 9, 2026, at 08:32, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> >
> > On Fri, Jan 9, 2026 at 2:11 AM Heikki Linnakangas <hlinnaka(at)iki(dot)fi> wrote:
> >>
> >> On 08/01/2026 15:10, Kirill Reshke wrote:
> >>> On Thu, 8 Jan 2026 at 17:31, Shinya Kato <shinya11(dot)kato(at)gmail(dot)com> wrote:
> >>>> In copy.c, nodeTag was being compared directly, so I replaced it with
> >>>> the IsA() predicate macro for consistency.
> >>>
> >>> Oops. Looks like oversight in 6c8f670. This is indeed case where we
> >>> should use IsA()
> >>>
> >>>> I verified that there are no other direct comparisons left by running
> >>>> the following command:
> >>>> $ git grep "nodeTag(.*) =="
> >>>
> >>> Yep, look like this is the only case in copy.c
> >
> > I found a similar issue in define.c. Should we fix it there as well?
> >
> > diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c
> > index 63601a2c0b4..8313431397f 100644
> > --- a/src/backend/commands/define.c
> > +++ b/src/backend/commands/define.c
> > @@ -349,7 +349,7 @@ defGetStringList(DefElem *def)
> > (errcode(ERRCODE_SYNTAX_ERROR),
> > errmsg("%s requires a parameter",
> > def->defname)));
> > - if (nodeTag(def->arg) != T_List)
> > + if (!IsA(def->arg, List))
> > elog(ERROR, "unrecognized node type: %d", (int)
> > nodeTag(def->arg));
> >
> > foreach(cell, (List *) def->arg)
> >
> > Regards,
> >
> > --
> > Fujii Masao
>
> Yep, I did a search with `nodeTag\(.*\)\s+(?:!=|==).*`, and this is the only finding.

Yeah, I was going to submit the exact same patch detected with the help of
[1]. That's the only remaining case.

[1]: https://github.com/bdrouvot/coccinelle_on_pg/blob/main/misc/nodetag.cocci

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Japin Li 2026-01-09 06:04:49 Re: [PATCH] Add pg_get_role_ddl() functions for role recreation
Previous Message Andrey Borodin 2026-01-09 05:40:11 Re: GIN pageinspect support for entry tree and posting tree