zed icon indicating copy to clipboard operation
zed copied to clipboard

SQL: Using GROUP BY column in math

Open philrz opened this issue 8 months ago • 0 comments

tl;dr

The following query works in Postgres but not SuperDB.

SELECT i, i + 10 FROM integers GROUP BY i ORDER BY i;

Details

Repro is with super commit 3c0e543. This was found via a query from a sqllogictest.

Repro with test data:

$ super -version
Version: 3c0e54399

$ cat integers.sup 
{i:3(int32),j:4(int32)}
{i:3(int32),j:4(int32)}
{i:2(int32),j:4(int32)}

$ super -c "
SELECT i, i + 10 FROM 'integers.sup' GROUP BY i ORDER BY i;"

no corresponding grouping element for non-aggregate "i+10" at line 2, column 11:
SELECT i, i + 10 FROM 'integers.sup' GROUP BY i ORDER BY i;

Here it is working in Postgres:

$ psql postgres
psql (17.5 (Homebrew))
Type "help" for help.

$ psql postgres
psql (17.5 (Homebrew))
Type "help" for help.

postgres=# SELECT * FROM integers;
 i | j 
---+---
 3 | 4
 3 | 4
 2 | 4
(3 rows)

postgres=# SELECT i, i + 10 FROM integers GROUP BY i ORDER BY i;
 i | ?column? 
---+----------
 2 |       12
 3 |       13
(2 rows)

philrz avatar Jun 21 '25 21:06 philrz