LucidDB / luciddb

DEFUNCT: See README
https://github.com/LucidDB/luciddb
Apache License 2.0
53 stars 24 forks source link

[FRG-230] validator can't deal with duplicate column aliases in nested selects #642

Open dynamobi-build opened 12 years ago

dynamobi-build commented 12 years ago

[reporter="jvs", created="Wed, 1 Nov 2006 00:17:47 -0500 (GMT-05:00)"] This case is mostly of academic interest (only managed to hit it because of a sampling SQL generator which sticks unnecessary select * on top of things).

select * from (select empno as x, deptno as x from sales.emps);

Both columns come back with the same results, which is incorrect. But

select empno as x, deptno as x from sales.emps;

does fine. The problem is that when SqlValidator expands the select *, it needs to make up SqlIdentifiers to reference the inner columns, but there's no way to do that unambiguously. However, there is no ambiguity at the SQL level (and SQL:2003 allows for duplicate column aliases as long as there is no ambiguity from the point of view of outer queries).

Rewrite the inner column aliases to make them unique, and fix up references? Yuck.

dynamobi-build commented 12 years ago

[author="jhyde", created="Wed, 1 Nov 2006 13:51:55 -0500 (GMT-05:00)"] I think this query is invalid. "select *" is expanded to "select x, x", and those "x" references are invalid. Do you agree?

dynamobi-build commented 12 years ago

[author="jvs", created="Wed, 1 Nov 2006 14:11:03 -0500 (GMT-05:00)"] I'm afraid it's probably valid.

SQL:2003 Part 2 Section 7.12 Syntax Rule 3.b:

 "Otherwise, the