-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
having
shouldn't include alias in projection
#4556
Comments
having
is wronghaving
shouldn't include alias in projection
But, pg allow it's a complex things. -- create
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
age INTEGER NOT NULL,
name TEXT NOT NULL
);
-- insert
INSERT INTO EMPLOYEE VALUES (0001, 0020, 'Sales');
--ok
select max(empId), age as a from EMPLOYEE group by a;
--failed
select max(empId), age as a from EMPLOYEE group by a having a > 3;
-- ok
select max(empId), (age + empId) as a from EMPLOYEE group by a;
-- failed
select max(empId), (age as a + empId) from EMPLOYEE group by (a + empId);
psql:commands.sql:13: ERROR: syntax error at or near "as"
|
cc @Dandandan @alamb @andygrove @mingmwang . I don't know if this is a bug or a feature and how we should do it better. |
@jackwener Maybe you can refer to this https://docs.snowflake.com/en/sql-reference/constructs/having.html Per SnowFlake's doc, HAVING should apply to expressions produced by the GROUP BY. Some other docs for you to refer about the evaluation ordering of operators: https://docs.snowflake.com/en/sql-reference/constructs/qualify.html |
As @mingmwang -- exprs in the |
|
@jackwener what else is needed other than #4579 to close this issue? |
Describe the bug
When I try to refactor the planner having, I find the
having
planner is wrong.1147 line in planner.rs
// This step "dereferences" any aliases in the HAVING clause.
In fact,
having
can't access the projection alias (becausehaving
is before theselect
).having is
just
filter group results, it can't get alias in projection.for example:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: