Skip to content

Unambiguous Column Reference Error Not Triggered in SQL Query #21232

@xiedeyantu

Description

@xiedeyantu

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions