alamb opened a new issue #1479:
URL: https://github.com/apache/arrow-datafusion/issues/1479


   **Describe the bug**
   You can not refer to an aggregate directly in the ORDER BY clause
   
   **To Reproduce**
   ```shell
   echo "1" > /tmp/foo.csv
   cargo run datafusion-cli
   ```
   
   ```sql
   DataFusion CLI v5.1.0
   
   ❯ create external table foo(x int) stored as CSV location '/tmp/foo.csv';
   0 rows in set. Query took 0.033 seconds.
   
   ❯ select min(foo) from foo order by 1;
   Plan("Invalid identifier '#foo' for schema foo.x")
   ```
   
   **Expected behavior**
   The query should produce a single column, with a single row `1`
   
   Note there are several workarounds to express this query that do work:
   
   Refer to the item by index:
   
   ```sql
   ❯ select min(x) from foo order by 1;
   +------------+
   | MIN(foo.x) |
   +------------+
   | 1          |
   +------------+
   1 row in set. Query took 0.045 seconds.
   ```
   
   Given the query an alias:
   ```sql
   ❯ select min(x) as min_x from foo order by min_x;
   +-------+
   | min_x |
   +-------+
   | 1     |
   +-------+
   1 row in set. Query took 0.010 seconds.
   ```
   
   **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