BUG #16212: subquery block allows to overwrite table alias defined earlier - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #16212: subquery block allows to overwrite table alias defined earlier
Date
Msg-id 16212-cc31996adcf45996@postgresql.org
Whole thread Raw
Responses Re: BUG #16212: subquery block allows to overwrite table alias defined earlier  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: BUG #16212: subquery block allows to overwrite table aliasdefined earlier  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      16212
Logged by:          Denis Girko
Email address:      luza.mbox@gmail.com
PostgreSQL version: 9.6.16
Operating system:   Linux
Description:

Short example to illustrate the issue:

SELECT
   a,
   b.p,
   c.p
FROM
  (VALUES (1)) a
  JOIN LATERAL (
    SELECT p FROM (VALUES (2)) p
  ) b ON TRUE
  JOIN LATERAL (
    SELECT p FROM (VALUES (3)) p
  ) c ON TRUE
;

Expected result ((1), (2), (3))
Actual result ((1), (2), (2)).
("p" introduced in second JOIN overwrites the one defined by first)
Regular JOIN (not LATERAL) is not the subject of such an issue.


Another example:
SELECT
   a,
   b.a
FROM
  (VALUES (1)) a
  JOIN (
    SELECT a FROM (VALUES (2)) a
  ) b ON TRUE
;

Expected result ((1), (2))
Actual result ((2), (2)).
(JOIN overwrites the "a" defined before)
Both regular and lateral JOIN show the same behaviour.

Scalars also can cause the same result:

SELECT
   a,
   b.a
FROM
  (VALUES (1)) a
  JOIN (
    SELECT 2 AS a
  ) b ON TRUE
;

Expected result ((1), 2)
Actual result (2, 2).


pgsql-bugs by date:

Previous
From: Christophe Pettus
Date:
Subject: Re: BUG #16205: background worker "logical replication worker" (PID25218) was terminated by signal 11: Segmentation
Next
From: PG Bug reporting form
Date:
Subject: BUG #16213: segfault when running a query