Re: Merge command is erroring with: PlaceHolderVar found where not expected

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Önder Kalacı <onderkalaci@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2023-03-15T14:48:21Z
Lists: pgsql-bugs
=?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= <onderkalaci@gmail.com> 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



Commits

  1. Support PlaceHolderVars in MERGE actions.