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 1pcSQY-0000Nc-0x for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Mar 2023 14:48:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pcSQV-0008BF-33 for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Mar 2023 14:48:27 +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 1pcSQU-00089i-Qp for pgsql-bugs@lists.postgresql.org; Wed, 15 Mar 2023 14:48:26 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcSQS-0006VG-B6 for pgsql-bugs@lists.postgresql.org; Wed, 15 Mar 2023 14:48:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 32FEmLRg3204630; Wed, 15 Mar 2023 10:48:22 -0400 From: Tom Lane To: =?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= cc: pgsql-bugs@lists.postgresql.org Subject: Re: Merge command is erroring with: PlaceHolderVar found where not expected In-reply-to: References: Comments: In-reply-to =?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= message dated "Wed, 15 Mar 2023 15:24:18 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3204628.1678891701.1@sss.pgh.pa.us> Date: Wed, 15 Mar 2023 10:48:21 -0400 Message-ID: <3204629.1678891701@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= writes: > CREATE TABLE source (id integer, z int); > CREATE TABLE target (id integer, z int); > MERGE INTO public.target sda USING ((SELECT source.id, source.z, 12 AS rnd > FROM public.source source) sdn FULL JOIN public.source sdn2 ON ((sdn.id > OPERATOR(pg_catalog.=) sdn2.id))) ON (sda.id OPERATOR(pg_catalog.=) sdn.id) > WHEN NOT MATCHED THEN INSERT (id, z) VALUES (sdn.id, sdn.rnd); > *ERROR: PlaceHolderVar found where not expected* Thanks for the report! Somebody was far too optimistic here: * Add resjunk entries for any Vars used in each action's * targetlist and WHEN condition that belong to relations other * than target. Note that aggregates, window functions and * placeholder vars are not possible anywhere in MERGE's WHEN * clauses. (PHVs may be added later, but they don't concern us * here.) I'm not sure offhand whether RECURSE or INCLUDE is the more appropriate action. regards, tom lane