Re: [HACKERS] SUM() and GROUP BY

Поиск
Список
Период
Сортировка
От Thomas G. Lockhart
Тема Re: [HACKERS] SUM() and GROUP BY
Дата
Msg-id 369C3AC2.D8961D08@alumni.caltech.edu
обсуждение исходный текст
Ответ на SUM() and GROUP BY  ("D'Arcy" "J.M." Cain <darcy@druid.net>)
Ответы Re: [HACKERS] SUM() and GROUP BY  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Clark Evans
Дата:
Сообщение: Re: [HACKERS] Re: EXCEPT/INTERSECT for v6.4
Следующее
От: "Thomas G. Lockhart"
Дата:
Сообщение: Re: [HACKERS] Re: EXCEPT/INTERSECT for v6.4