jackwener opened a new issue, #4556:
URL: https://github.com/apache/arrow-datafusion/issues/4556

   **Describe the bug**
   
   When I try to refactor the planner having, I find the `having` planner is 
wrong.
   
   1147 line in planner.rs
   ```rust
   // 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:
   ```sql
   -- 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to