dolt icon indicating copy to clipboard operation
dolt copied to clipboard

References in GROUP BY / HAVING should be allowed to match SELECT aliases.

Open nicktobey opened this issue 8 months ago • 0 comments

Reproduction steps:

CREATE table xy (x int primary key, y int, unique index y_idx(y));
insert into xy values (1,0), (2,1), (0,2), (3,3);
select y as z from xy group by (y) having AVG(z) > 0;

MySQL output:

+------+
| z    |
+------+
|    1 |
|    2 |
|    3 |
+------+

Dolt output:

column "z" could not be found in any table in scope.

When resolving references in aggregate expressions, MySQL prefers binding to table columns over SELECT aliases. But it can still bind to a SELECT alias if no table column matches. The above example should work by binding z to the y as z alias in the SELECT.

nicktobey avatar Dec 04 '23 23:12 nicktobey