Robert Haas <robertmhaas@gmail.com> writes:
> Suppose you do this:
> create table animals (id serial primary key, name varchar not null);
> Then you can do this:
> with beings as (select * from animals) select * from beings where id = 1;
> But not this:
> with beings as (select * from animals a1, animals a2) select * from
> beings where id = 1;
No different from
regression=# select * from (animals a1 cross join animals a2) x where id = 1;
ERROR: column reference "id" is ambiguous
LINE 1: ...ct * from (animals a1 cross join animals a2) x where id = 1;
^
There's no way to access the a1/a2 aliases here, either; and that rule
goes back to SQL92 or maybe further.
regards, tom lane