Agregate Problem? - Mailing list pgsql-sql

From Len Morgan
Subject Agregate Problem?
Date
Msg-id 000501bee726$b7aa08e0$0908a8c0@H233.bstx.com
Whole thread Raw
Responses Re: [SQL] Agregate Problem?
List pgsql-sql
I am having a problem with queries that have an aggregate (sum in this case)
when no rows meet my criteria.  I still get back a row with null values for
all fields.  Is this the correct behavior?  I am trying to sum up daily
sales quanties by items and if I don't have any sales on a particular day, I
want to print nothing.  I thought I could do this by detecting a 0 row count
but since I have the aggregates, I still 1 row.

Example:

SELECT itemno,sum(qty) FROM sales WHERE sale_date = 'now()::date'

I would expect to get back zero rows if there were no sales today but I get
back 1.  Of course I also get back 1 row if I only sold 1 item.  Is this a
bug or a "feature?"

Thanks

Len Morgan



pgsql-sql by date:

Previous
From: Herouth Maoz
Date:
Subject: Re: [SQL] err: select f() from i where (f()) in (select f() from x group by j);
Next
From: Herouth Maoz
Date:
Subject: Re: [SQL] Agregate Problem?