Bug or feature? select, count(*), group by and empty tables - Mailing list pgsql-hackers

From Don Baccus
Subject Bug or feature? select, count(*), group by and empty tables
Date
Msg-id 3.0.1.32.19991214161139.01074db0@mail.pacifier.com
Whole thread Raw
In response to Re: [HACKERS] Re: [PATCHES] createdb/dropdb fixes  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] Bug or feature? select, count(*), group by and empty tables
List 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@pacifier.com> Nature photos, on-line guides, Pacific Northwest Rare Bird Alert
Serviceand other goodies at http://donb.photo.net.
 


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] Re: [PATCHES] createdb/dropdb fixes
Next
From: Don Baccus
Date:
Subject: Re: [HACKERS] Bug or feature? select, count(*), group by and empty tables