Re: Re: BUG #8444: ERROR: table name "tblb" specified more than once in subquery - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Re: BUG #8444: ERROR: table name "tblb" specified more than once in subquery
Date
Msg-id 1080.1379085600@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #8444: ERROR: table name "tblb" specified more than once in subquery  (David Johnston <polobo@yahoo.com>)
Responses Re: BUG #8444: ERROR: table name "tblb" specified more than once in subquery  (David Johnston <polobo@yahoo.com>)
List pgsql-bugs
David Johnston <polobo@yahoo.com> writes:
>> Here is a minimal query that demonstrates the problem.  In 9.1 it works:
>>
>> chris=# select * FROM current_user u join (current_user u cross join
>> current_user v) x on true;
>>
>> On 9.3 it fails:
>> ERROR:  table name "u" specified more than once

This is an intentional change that came in with the LATERAL feature.
The query is illegal per SQL spec but we used to allow it anyway,
on the theory that the table name "u" inside the aliased join "x"
wasn't visible anywhere that the other "u" was visible, so the
duplicate alias name was harmless.  But in the presence of LATERAL
it's not harmless; consider

select * FROM current_user u join
  (current_user u cross join LATERAL (select u.x) v) x on true;

Which instance of "u" does the lateral reference refer to?

(I think there was some discussion of this in the pgsql-hackers list
about a year ago, but I couldn't find it in a desultory search.)

            regards, tom lane

pgsql-bugs by date:

Previous
From: dqwhappyday@163.com
Date:
Subject: BUG #8446: CST FATAL: the database system is in recovery mode
Next
From: David Johnston
Date:
Subject: Re: BUG #8444: ERROR: table name "tblb" specified more than once in subquery