Re: MERGE ... WHEN NOT MATCHED BY SOURCE

Dean Rasheed <dean.a.rasheed@gmail.com>

From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Vik Fearing <vik@postgresfriends.org>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-03-21T12:24:31Z
Lists: 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



Commits

  1. Add support for MERGE ... WHEN NOT MATCHED BY SOURCE.

  2. Reindex toast before its main relation in reindex_relation()