Re: Allow an alias to be attached directly to a JOIN ... USING
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2019-08-01T06:33:50Z
Lists: pgsql-hackers
On Tue, Jul 16, 2019 at 8:58 AM Fabien COELHO <coelho@cri.ensmp.fr> wrote: > About the feature: > > When using aliases both on tables and on the unifying using clause, the former > are hidden from view. I cannot say that I understand why, and this makes it > impossible to access some columns in some cases if there is an ambiguity, eg: > > postgres=# SELECT t.filler > FROM pgbench_tellers AS t > JOIN pgbench_branches AS b USING (bid) AS x; > ERROR: invalid reference to FROM-clause entry for table "t" > LINE 1: SELECT t.filler FROM pgbench_tellers AS t JOIN pgbench_branc... > ^ > HINT: There is an entry for table "t", but it cannot be referenced from this > part of the query. > > But then: > > postgres=# SELECT x.filler > FROM pgbench_tellers AS t > JOIN pgbench_branches AS b USING (bid) AS x; > ERROR: column reference "filler" is ambiguous > LINE 1: SELECT x.filler FROM pgbench_tellers AS t JOIN pgbench_branc... > ^ > > Is there a good reason to forbid several aliases covering the same table? > > More precisely, is this behavior expected from the spec or a side effect > of pg implementation? Indeed, that seems like a problem, and it's a good question. You can see this on unpatched master with SELECT x.filler FROM (pgbench_tellers AS t JOIN b USING (bid)) AS x. I'm moving this to the next CF. -- Thomas Munro https://enterprisedb.com
Commits
-
Allow an alias to be attached to a JOIN ... USING
- 055fee7eb4dc 14.0 landed
-
Add p_names field to ParseNamespaceItem
- 66392d396508 14.0 landed