zed
zed copied to clipboard
SQL: ORDER BY aggregation that does not appear in SELECT clause
The following query works in Postgres but not SuperDB.
SELECT b, SUM(a) FROM test GROUP BY b ORDER BY COUNT(a);
Details
Repro is with super commit e75dfda. This was found via a query from a sqllogictest.
Repro with test data:
$ super -version
Version: e75dfdaf1
$ cat test.sup
{a:11::int32,b:22::int32}
{a:13::int32,b:22::int32}
{a:12::int32,b:21::int32}
$ super -c "
SELECT b, SUM(a) FROM 'test.sup' GROUP BY b ORDER BY COUNT(a);"
column "a": does not exist at line 2, column 60:
SELECT b, SUM(a) FROM 'test.sup' GROUP BY b ORDER BY COUNT(a);
~
Here it is working in Postgres:
$ psql postgres
psql (17.5 (Homebrew))
Type "help" for help.
postgres=# SELECT * FROM test;
a | b
----+----
11 | 22
13 | 22
12 | 21
(3 rows)
postgres=# SELECT b, SUM(a) FROM test GROUP BY b ORDER BY COUNT(a);
b | sum
----+-----
21 | 12
22 | 24
(2 rows)