Re: strange sum behaviour

From: "John D(dot) Burger" <john(at)mitre(dot)org>
To: "Andrew Baerg" <andrew(dot)baerg(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: strange sum behaviour
Date: 2006-08-29 18:29:06
Message-ID: ba6070e5dc737f2c2b64c10483297461@mitre.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andrew Baerg wrote:

> corp=# select amount from acc_trans where trans_id=19721 and
> chart_id=10019;
> amount
> ---------
> 4.88
> 117.1
> -121.98
> (3 rows)
>
> corp=# select sum(amount) from acc_trans where trans_id=19721 and
> chart_id=10019;
> sum
> ----------------------
> -1.4210854715202e-14
> (1 row)
>

This has nothing to do with SUM():

> select 4.88::float + 117.1::float + -121.98::float;
?column?
----------------------
-1.4210854715202e-14
(1 row)

It's just the inherent inexactness of floating point, and probably not
even particular to Postgres.

- John D. Burger
MITRE

In response to

Browse pgsql-general by date

  From Date Subject
Next Message garry saddington 2006-08-29 18:35:27 counting days
Previous Message codeWarrior 2006-08-29 18:19:30 Re: strange sum behaviour