Re: [SQL] Agregate Problem?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
Cc: "Len Morgan" <len-morgan(at)crcom(dot)net>, pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Agregate Problem?
Date: 1999-08-15 15:48:41
Message-ID: 10079.934732121@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)oumail(dot)openu(dot)ac(dot)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

Browse pgsql-sql by date

  From Date Subject
Next Message Matthew Hagerty 1999-08-16 02:58:36 Stepping through a table.
Previous Message Ross J. Reedstrom 1999-08-15 15:36:26 Re: [SQL] Multiple values for a field