Jesse-Bakker opened a new issue, #8391:
URL: https://github.com/apache/arrow-datafusion/issues/8391

   ### Describe the bug
   
   When using an un-aliased name in an `ORDER BY` clause, while that name is 
aliased to the same name in a projection, datafusion raises an 
`AmbiguousReference` error.
   
   If the name is not manually aliased, or the aliased name is used, no error 
is raised.
   
   ### To Reproduce
   
   datafusion-cli:
   ```
   ❯ CREATE TABLE t (a INTEGER);
   0 rows in set. Query took 0.003 seconds.
   ❯ SELECT t.a AS a FROM t ORDER BY t.a;
   Schema error: Schema contains qualified field name t.a and unqualified field 
name a which would be ambiguous
   ```
   
   The following variations do not raise an error:
   ```sql
   SELECT a FROM t ORDER BY a;
   SELECT a FROM t ORDER BY t.a;
   SELECT t.a FROM t ORDER BY a;
   SELECT t.a FROM t ORDER BY t.a;
   SELECT t.a AS a FROM t ORDER BY a;
   ```
   
   ### Expected behavior
   
   The result of the query `SELECT t.a AS a FROM t ORDER BY t.a` should be the 
same as from, for example `SELECT t.a AS a FROM t ORDER BY a` and `SELECT t.a 
FROM t ORDER BY t.a`
   
   ### Additional context
   
   _No response_


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