Re: Anomaly with SUM().

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Anthony Best <abest(at)digitalflex(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Anomaly with SUM().
Date: 2003-08-08 19:50:55
Message-ID: 29414.1060372255@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Anthony Best <abest(at)digitalflex(dot)net> writes:
> I've noticed that the SUM() seems to overflow under some situations.
> The only difference is the order that the data is retrived from the
> database.

> accounting=# select sum(amount) from transactions, chart WHERE
> account=chart.id;
> sum
> ---------------------
> 5.6843418860808e-14
> (1 row)

> accounting=# select sum(amount) from transactions, chart WHERE
> account=chart.id AND amount=amount;
> sum
> -----
> 0
> (1 row)

That's not an overflow, it's merely roundoff error. If this surprises
you, possibly you should be using type NUMERIC instead of float.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Anthony Best 2003-08-08 20:01:15 Re: Anomaly with SUM().
Previous Message Dennis Gearon 2003-08-08 19:28:56 Re: Anomaly with SUM().