Re: Postgresql problem with update double precision

From: Jerry Sievers <gsievers19(at)comcast(dot)net>
To: <condor(at)stz-bg(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Postgresql problem with update double precision
Date: 2011-08-05 11:20:01
Message-ID: 8739hgcdge.fsf@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Condor <condor(at)stz-bg(dot)com> writes:

> Hello ppl,
> for few years I have problem when update double precision field. I
> have table and few double precision columns, here is example:
>
> sumall double precision,
> sumin double precision,
>
> My php script do:
>
> $get = 2.40
>
> and sql code is:
>
> UPDATE table1 SET sumall = sumall + $get WHERE id = 1 AND rd =
> CURRENT_DATE;
>
>
> When I browse the table some times i see incorrect values like:
>
> 955.599999999998
>
> it's should be 955.60 after these updates ... some days is fine, some
> days the value is incorrect.
>
> I have this problem from version 7 of postgresql, Im now use 9.0.3
>
> Anyone know what can be the problem and why some times records is
> fine, some times isnt ?

That floating point data types are inexact is a well known problem
with them and not Postgres specific.

Consider switching those fields to type NUMERIC.

HTH
>

--
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres(dot)consulting(at)comcast(dot)net
p: 305.321.1144

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Black 2011-08-05 11:23:52 Re: Select count with offset returns nothing.
Previous Message Misa Simic 2011-08-05 11:01:28 Re: Select count with offset returns nothing.