Skip to content

SQL: Aggregate without GROUP BY on empty input #6506

@philrz

Description

@philrz

As I understand it, the SQL standard indicates there should be at least one row returned on aggregations without GROUP BY, even if the input is empty. Instead SuperDB is currently still doing what it's traditionally done in pipe context, which is to return nothing.

Details

Repro is with super commit a021857. This effect surfaces in sqllogictests such as random/aggregates/slt_good_0/q343 and random/aggregates/slt_good_0/q464.

Here's two simplified repro examples that both return nothing with super:

$ super -version
Version: a021857b4

$ super -c "SELECT COUNT(*) WHERE FALSE;"
[no output]

$ super -c "SELECT SUM(1) WHERE FALSE;"
[no output]

Whereas in Postgres, these return 0 and NULL, respectively.

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

postgres=# \pset null 'NULL'
Null display is "NULL".
postgres=# SELECT COUNT(*) WHERE FALSE;
 count 
-------
     0
(1 row)

postgres=# SELECT SUM(1) WHERE FALSE;
 sum  
------
 NULL
(1 row)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions