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

From Alvaro Herrera
Subject Re: MERGE ... WHEN NOT MATCHED BY SOURCE
Date
Msg-id 20230321102849.ajmumhbngak3ltkw@alvherre.pgsql
Whole thread Raw
In response to Re: MERGE ... WHEN NOT MATCHED BY SOURCE  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: MERGE ... WHEN NOT MATCHED BY SOURCE
List pgsql-hackers
On 2023-Mar-19, Dean Rasheed wrote:

> diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
> new file mode 100644
> index efe88cc..e1ebc8d
> --- a/src/backend/parser/gram.y
> +++ b/src/backend/parser/gram.y

> +merge_when_tgt_matched:
> +            WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
> +            | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
> +        ;

I think a one-line comment on why this "matched" production matches "NOT
MATCHED BY" would be useful.  I think you have a big one in
transformMergeStmt already.


> +            /* 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?

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
"El miedo atento y previsor es la madre de la seguridad" (E. Burke)



pgsql-hackers by date:

Previous
From: "shiy.fnst@fujitsu.com"
Date:
Subject: RE: Dropped and generated columns might cause wrong data on subs when REPLICA IDENTITY FULL
Next
From: Amit Kapila
Date:
Subject: Re: Initial Schema Sync for Logical Replication