Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1peZEg-0000d5-MC for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Mar 2023 10:28:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1peZEf-0006RP-6e for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Mar 2023 10:28:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1peZEe-0006RG-TK for pgsql-hackers@lists.postgresql.org; Tue, 21 Mar 2023 10:28:56 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1peZEc-00054b-G2 for pgsql-hackers@lists.postgresql.org; Tue, 21 Mar 2023 10:28:55 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id E70053200C24; Tue, 21 Mar 2023 06:28:52 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 21 Mar 2023 06:28:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1679394532; x= 1679480932; bh=bXq/3S4F169J/cESOmqvNsktItWatruBW8KmjES+bfA=; b=u iLFcrir+V52AlPueXKg2BiLxP17Q8tCqmmCaxNpD7hXVzY8jlnGawwztQYU4F4ao MZKoafYRoSjGZ6TxGyaS6PwexHVaRQtyTJkT6iqliVIwrUlVFNS0iRGFtE8GTdN1 6LQZwtd1oHutnNheGfdjDaSaRjshOh6V6kRr3ANyPFDh4Tvt5Wjx1RKBOhHeFQY0 YAh4ybqmVOhDi3TVnGJBmxKpbFvhxKQqfdrjTORyX6N/G4A82EUSoJU1ULMJHoGe lLIRuq1OINjQZmdJ9yOFyN3tVaYt+9CQim4uiMIVA28djEIQ9cnEazZysgrCaUWw HuzVsCRuzExirBzWofjuw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdegtddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 21 Mar 2023 06:28:51 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id CF00A386; Tue, 21 Mar 2023 11:28:49 +0100 (CET) Date: Tue, 21 Mar 2023 11:28:49 +0100 From: Alvaro Herrera To: Dean Rasheed Cc: Vik Fearing , PostgreSQL Hackers Subject: Re: MERGE ... WHEN NOT MATCHED BY SOURCE Message-ID: <20230321102849.ajmumhbngak3ltkw@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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)