BUG #18871: Cross-partition MERGE fails with unclear internal error

PG Bug reporting form <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: exclusion@gmail.com
Date: 2025-03-28T05:00:01Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18871
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 17.4
Operating system:   Ubuntu 24.04
Description:        

The following script:
CREATE TABLE pt(a int, b int) PARTITION BY LIST(a);
CREATE TABLE p1 PARTITION OF pt FOR VALUES IN (a);

MERGE INTO pt USING (SELECT 2 AS a) AS q ON pt.a = q.a
    WHEN NOT MATCHED THEN INSERT VALUES (1, 2)
    WHEN MATCHED THEN DO NOTHING;
fails with:
ERROR:  XX000: unknown action in MERGE WHEN clause
LOCATION:  ExecInitPartitionInfo, execPartition.c:962

This error is triggered on REL_15_STABLE (starting from bf5c4b3d9) ..
master.
Before bf5c4b3d9, the MERGE produced ERROR:  variable not found in subplan
target lists.

This anomaly is discovered with SQLsmith.

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix MERGE with DO NOTHING actions into a partitioned table.