zed icon indicating copy to clipboard operation
zed copied to clipboard

SQL: Using an alias identical to a column name

Open philrz opened this issue 8 months ago • 0 comments

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

Repro with test data:

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

$ super -version
Version: 944989687

$ super -c "SELECT 1 AS i, SUM(i) FROM 'integers.sup' GROUP BY i ORDER BY 2;"
{i:1,"SUM(i)":8}

Whereas in Postgres:

$ 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 1 AS i, SUM(i) FROM integers GROUP BY i ORDER BY 2;
 i | sum 
---+-----
 1 |   2
 1 |   6
(2 rows)

philrz avatar Jun 23 '25 18:06 philrz