Re: [HACKERS] SUM() and GROUP BY

From: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] SUM() and GROUP BY
Date: 1999-01-13 06:18:42
Message-ID: 369C3AC2.D8961D08@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Does this seem right?
> druid=> SELECT client_id, SUM(tramount)
> FROM acctrans GROUP BY client_id;
> client_id|sum
> ---------+---
> |
> (1 row)
> If there are no rows in the table then shouldn't the result be no rows
> when GROUP BY is used? Further, What about this?

Not sure. Someone may want to try this query on another DB. I know the
answer to the next one though...

> druid=> SELECT SUM(tramount) FROM acctrans;
> sum
> ---
>
> (1 row)
> Shouldn't that be 0.00?

No. It is returning NULL, because NULL means "don't know". It doesn't
mean "nothing" or "zero". That is certainly the correct behavior if the
table were populated with all NULLs in that column. And by extension, it
is the correct result if there are no rows at all, since "don't know"
for a bunch should give the same result as "don't know" for a few or for
none.

> What will the NUMERIC or DECIMAL types do in these situations? It
> looks like INTEGER has the same behaviour as MONEY (which tramount
> is.)

They will all behave the same.

- Tom

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas G. Lockhart 1999-01-13 06:34:42 Re: [HACKERS] Re: EXCEPT/INTERSECT for v6.4
Previous Message Clark Evans 1999-01-13 06:04:15 Re: [HACKERS] Re: EXCEPT/INTERSECT for v6.4