1fanwang commented on PR #5225:
URL: https://github.com/apache/calcite/pull/5225#issuecomment-5444308258

   > SELECT max(sal) AS sal, deptno, job FROM emp GROUP BY deptno, job ORDER BY 
max(sal);
   > 
   > postgresql can return result, instead of throw error
   
   Thanks for raising this @iwanttobepowerful 
   
   PostgreSQL and Calcite resolve this query differently.
   
   PostgreSQL only recognizes an output alias when it appears by itself in 
`ORDER BY`. In `ORDER BY max(sal)`, `sal` therefore refers to the input column, 
so the query succeeds.
   
   Calcite allows SELECT aliases inside `ORDER BY` expressions. Since the query 
defines `max(sal) AS sal`, Calcite expands the expression to `max(max(sal))`, 
which is invalid.
   
   Right now this PR proposes to keep Calcite's current resolution rules. It 
replaces the later planner failure with a clear validation error. 
   
   I think matching PostgreSQL would require a separate conformance change 
that's beyond the scope of this ticket/PR


-- 
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