Re: MERGE ... WHEN NOT MATCHED BY SOURCE - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: MERGE ... WHEN NOT MATCHED BY SOURCE
Date
Msg-id CAEZATCUR39xOOj5kj6nq4+Jj4N=q0bydHKaj_=aN0ACKpaiatA@mail.gmail.com
Whole thread Raw
In response to Re: MERGE ... WHEN NOT MATCHED BY SOURCE  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Responses Re: MERGE ... WHEN NOT MATCHED BY SOURCE
List pgsql-hackers
On Tue, 21 Mar 2023 at 10:28, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
>
> > +                     /* Combine it with the action's WHEN condition */
> > +                     if (action->qual == NULL)
> > +                             action->qual = (Node *) ntest;
> > +                     else
> > +                             action->qual =
> > +                                     (Node *) makeBoolExpr(AND_EXPR,
> > +                                                                               list_make2(ntest, action->qual),
> > +                                                                               -1);
>
> Hmm, I think ->qual is already in implicit-and form, so do you really
> need to makeBoolExpr, or would it be sufficient to append this new
> condition to the list?
>

No, this has come directly from transformWhereClause() in the parser,
so it's an expression tree, not a list. Transforming to implicit-and
form doesn't happen until later.

Looking at it with fresh eyes though, I realise that I could have just written

    action->qual = make_and_qual((Node *) ntest, action->qual);

which is equivalent, but more concise.

Regards,
Dean



pgsql-hackers by date:

Previous
From: Önder Kalacı
Date:
Subject: Re: Dropped and generated columns might cause wrong data on subs when REPLICA IDENTITY FULL
Next
From: Alvaro Herrera
Date:
Subject: Re: MERGE ... WHEN NOT MATCHED BY SOURCE