Describe the bug
In a subquery containing a JOIN operation, when the two joined tables share a column with the same name (such as age), the JOIN result set includes duplicate column names. If the outer query uses a simple select age to reference this duplicate column, the database system does not throw the expected "ambiguous column reference" error but instead allows the query to execute.
To Reproduce
Create two tables:
create table a(aid int, age int);
create table b(bid int, age int);
Execute the following query:
select age from (SELECT * FROM a join b on a.aid = b.bid) as t;
Observe the outcome: The query executes without error.
Expected behavior
Since the subquery t contains two columns named age (one from table a and the other from table b), the reference to age in the outer SELECT clause becomes ambiguous. The database system should throw a clear error, such as "Column 'age' in field list is ambiguous" or "ERROR: column reference 'age' is ambiguous".
Additional context
If we determine that this needs to be fixed, I will attempt to resolve the issue.
Describe the bug
In a subquery containing a JOIN operation, when the two joined tables share a column with the same name (such as age), the JOIN result set includes duplicate column names. If the outer query uses a simple
select ageto reference this duplicate column, the database system does not throw the expected "ambiguous column reference" error but instead allows the query to execute.To Reproduce
Create two tables:
Execute the following query:
Observe the outcome: The query executes without error.
Expected behavior
Since the subquery t contains two columns named age (one from table a and the other from table b), the reference to age in the outer SELECT clause becomes ambiguous. The database system should throw a clear error, such as "Column 'age' in field list is ambiguous" or "ERROR: column reference 'age' is ambiguous".
Additional context
If we determine that this needs to be fixed, I will attempt to resolve the issue.