pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19461: MERGE with EXISTS subquery referencing USING clause alias fails with "variable not found in subplan
2+ messages / 2 participants
[nested] [flat]
* BUG #19461: MERGE with EXISTS subquery referencing USING clause alias fails with "variable not found in subplan
@ 2026-04-20 09:29 PG Bug reporting form <noreply@postgresql.org>
2026-04-20 14:56 ` Re: BUG #19461: MERGE with EXISTS subquery referencing USING clause alias fails with "variable not found in subplan Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2026-04-20 09:29 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: 303677365@qq.com
The following bug has been logged on the website:
Bug reference: 19461
Logged by: chunling qin
Email address: 303677365@qq.com
PostgreSQL version: 15.0
Operating system: centos
Description:
## Summary
A MERGE statement that includes an EXISTS condition with a subquery
referencing an alias from the USING clause fails with the error: `ERROR:
variable not found in subplan target lists`.
## PostgreSQL Version
```
PostgreSQL 15devel on x86_64-pc-linux-gnu, compiled by clang version 17.0.6,
64-bit
```
Tested on REL_15_STABLE branch.
## Steps to Reproduce
```sql
-- Setup
DROP TABLE IF EXISTS t1, t2, t3 CASCADE;
CREATE TABLE t1 (col_int INT);
CREATE TABLE t2 (col_int INT);
CREATE TABLE t3 (col_int INT);
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (1);
INSERT INTO t3 VALUES (1);
-- Bug reproduction
MERGE INTO t1 t11
USING (t2 t12 NATURAL INNER JOIN t3 t13)
ON TRUE
WHEN MATCHED AND EXISTS (
SELECT 1
FROM (
SELECT col_int FROM t1
EXCEPT
SELECT col_int FROM t3 WHERE t13.col_int IS NOT NULL
) mm
) THEN DELETE;
```
## Expected Behavior
The MERGE statement should execute successfully. The EXISTS subquery
references `t13.col_int` from the USING clause, which should be valid within
the WHEN MATCHED condition context.
This issue could not be reproduced with the latest version, but we can
easily reproduced by PostgreSQL 15devel. I am submitting this report for
official confirmation.
postgres=# postgres=# postgres=# postgres-# postgres-# postgres-# postgres(#
postgres(# postgres(# postgres(# postgres(# postgres(# postgres(#
ERROR: variable not found in subplan target lists
postgres=# select version();
version
--------------------------------------------------------------------------------------
-------------------------------------------------
PostgreSQL 15devel on x86_64-pc-linux-gnu, compiled by clang version 17.0.6
(TencentO
S 17.0.6-8.tl4.ap.2), 64-bit (commit:7103ebb7aa
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #19461: MERGE with EXISTS subquery referencing USING clause alias fails with "variable not found in subplan
2026-04-20 09:29 BUG #19461: MERGE with EXISTS subquery referencing USING clause alias fails with "variable not found in subplan PG Bug reporting form <noreply@postgresql.org>
@ 2026-04-20 14:56 ` Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 0 replies; 2+ messages in thread
From: Laurenz Albe @ 2026-04-20 14:56 UTC (permalink / raw)
To: 303677365@qq.com; pgsql-bugs@lists.postgresql.org
On Mon, 2026-04-20 at 09:29 +0000, PG Bug reporting form wrote:
> PostgreSQL version: 15.0
Don't report bugs against old, outdated minor releases.
Test against 15.latest first.
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-04-20 14:56 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-04-20 09:29 BUG #19461: MERGE with EXISTS subquery referencing USING clause alias fails with "variable not found in subplan PG Bug reporting form <noreply@postgresql.org>
2026-04-20 14:56 ` Laurenz Albe <laurenz.albe@cybertec.at>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox