PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID16212
PG Version9.6.16
OSLinux
Opened2020-01-16 22:36:16+00
Reported byDenis Girko
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      16212
Logged by:          Denis Girko
Email address:      (redacted)
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).

Messages

DateAuthorSubject
2020-01-16 22:36:16+00PG Bug reporting formBUG #16212: subquery block allows to overwrite table alias defined earlier
2020-01-17 00:11:13+00Tom LaneRe: BUG #16212: subquery block allows to overwrite table alias defined earlier
2020-01-17 00:16:45+00"David G(dot) Johnston"Re: BUG #16212: subquery block allows to overwrite table alias defined earlier