Reporting a bug with the new MERGE statement. Tested against 75edb919613ee835e7680e40137e494c7856bcf9.
psql output as follows:
... psql:merge.sql:33: ERROR: variable not found in subplan target lists ROLLBACK [local] joe@joe=# \errverbose ERROR: XX000: variable not found in subplan target lists LOCATION: fix_join_expr_mutator, setrefs.c:2800
CREATE TABLE source (order_id, item_id, quantity, price) AS (SELECT order_id, item_id, incoming.quantity, incoming.price FROM item LEFT JOIN incoming USING (order_id, item_id));
MERGE INTO item a USING source b ON (a.order_id, a.item_id) = (b.order_id, b.item_id) WHEN NOT MATCHED THEN INSERT (order_id, item_id, quantity, price) VALUES (order_id, item_id, quantity, price) WHEN MATCHED AND a.* IS DISTINCT FROM b.* THEN UPDATE SET (quantity, price) = (b.quantity, b.price) WHEN MATCHED AND (b.quantity IS NULL AND b.price IS NULL) THEN DELETE; COMMIT;
It seems related to the use of a.* and b.*
That's right. The varattno is set to zero for whole-row Var. And in this case these whole-row Vars are not included in the targetlist.