Re: [SQL] Agregate Problem? - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] Agregate Problem?
Date
Msg-id 10079.934732121@sss.pgh.pa.us
Whole thread Raw
In response to Re: [SQL] Agregate Problem?  (Herouth Maoz <herouth@oumail.openu.ac.il>)
List pgsql-sql
> At 17:01 +0300 on 15/08/1999, Len Morgan wrote:
>> SELECT itemno,sum(qty) FROM sales WHERE sale_date = 'now()::date'

This is invalid as it stands --- you need "GROUP BY itemno" because of
the aggregate function.  (IIRC, Postgres versions before 6.5 were a bit
lax about checking for that error.)

>> 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?"

Herouth Maoz <herouth@oumail.openu.ac.il> writes:
> This is a correct behaviour when there is no GROUP BY. PostgreSQL does this
> in GROUP BY, too, unfortunately.

I believe we finally agreed that producing an empty row when there is a
GROUP BY is a bug (there was some debate about it).  I intend to change
that behavior for 6.6, but haven't actually done it yet...
        regards, tom lane


pgsql-sql by date:

Previous
From: "Ross J. Reedstrom"
Date:
Subject: Re: [SQL] Multiple values for a field
Next
From: Matthew Hagerty
Date:
Subject: Stepping through a table.