Bug or feature? select, count(*), group by and empty tables

From: Don Baccus <dhogaza(at)pacifier(dot)com>
To: <hackers(at)postgreSQL(dot)org>
Cc: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>, Postgres Hackers List <hackers(at)postgreSQL(dot)org>
Subject: Bug or feature? select, count(*), group by and empty tables
Date: 1999-12-15 00:11:39
Message-ID: 3.0.1.32.19991214161139.01074db0@mail.pacifier.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Here's another anomaly I've run across in porting the Ars Digita
Community System web development toolkit from Oracle to Postgres:

In oracle, if we do:

SQL> create table foo(i integer, j integer);

Table created.

then select like this, we get no rows returned:

SQL> select i, count(*) from foo group by i;

no rows selected

In postgres, the same select on the same empty table yields:

test=> select i, count(*) from foo group by i;
i|count
-+-----
| 0
(1 row)

test=>

Which is correct? It's the count() causing the row to be output,
apparently PostgreSQL feels obligated to return at least one
value for the aggragate and since there are no groups has to
invent one. I assume this is wrong, and that Oracle's right, but
haven't dug through Date's book to verify.

- Don Baccus, Portland OR <dhogaza(at)pacifier(dot)com>
Nature photos, on-line guides, Pacific Northwest
Rare Bird Alert Service and other goodies at
http://donb.photo.net.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Don Baccus 1999-12-15 00:32:55 Re: [HACKERS] Bug or feature? select, count(*), group by and empty tables
Previous Message Tom Lane 1999-12-14 23:44:15 Re: [HACKERS] Re: [PATCHES] createdb/dropdb fixes