Skip to content

having shouldn't include alias in projection #4556

@jackwener

Description

@jackwener

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 (because having is before the select).
having is just filter group results, it can't get alias in projection.

for example:

-- create
CREATE TABLE EMPLOYEE (
  empId INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  dept TEXT NOT NULL
);
-- insert
INSERT INTO EMPLOYEE VALUES (0001, 'Clark', 'Sales');
-- fetch 
select empId, length(name) as l FROM EMPLOYEE group by empId having l > 10;

psql:commands.sql:15: ERROR:  column "l" does not exist
LINE 1: ...ength(name) as l FROM EMPLOYEE group by empId having l > 10;

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions