Agregate Problem?

From: "Len Morgan" <len-morgan(at)crcom(dot)net>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Agregate Problem?
Date: 1999-08-15 14:01:36
Message-ID: 000501bee726$b7aa08e0$0908a8c0@H233.bstx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Herouth Maoz 1999-08-15 14:27:57 Re: [SQL] Agregate Problem?
Previous Message Herouth Maoz 1999-08-15 13:40:36 Re: [SQL] err: select f() from i where (f()) in (select f() from x group by j);