Re: strange sum behaviour - Mailing list pgsql-general

From Karen Hill
Subject Re: strange sum behaviour
Date
Msg-id 1156872665.455452.289830@m73g2000cwd.googlegroups.com
Whole thread Raw
In response to strange sum behaviour  ("Andrew Baerg" <andrew.baerg@gmail.com>)
List pgsql-general
"Andrew Baerg" wrote:
> Hi,
>
> I am getting strange results from the sum function as follows:
>
> 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)
>
>
> amount is defined as double precision. I noticed that if I cast amount
> as numeric, the sum comes out 0 as expected.
>


You are using the wrong datatype if you are working with currency.  Use
Numeric or Decimal instead.  The "money" type is depreciated.

http://www.postgresql.org/docs/8.1/interactive/datatype-money.html


pgsql-general by date:

Previous
From: "Jasbinder Bali"
Date:
Subject: Re: Shared Objects (Dynamic loading)
Next
From: "codeWarrior"
Date:
Subject: Re: strange sum behaviour