Re: Postgresql problem with update double precision - Mailing list pgsql-general

From Igor Neyman
Subject Re: Postgresql problem with update double precision
Date
Msg-id F4C27E77F7A33E4CA98C19A9DC6722A207E5E51E@EXCHANGE.corp.perceptron.com
Whole thread Raw
In response to Postgresql problem with update double precision  (Condor <condor@stz-bg.com>)
Responses Re: Postgresql problem with update double precision  (Chris Travers <chris.travers@gmail.com>)
List pgsql-general

> -----Original Message-----
> From: Condor [mailto:condor@stz-bg.com]
> Sent: Friday, August 05, 2011 6:49 AM
> To: pgsql-general@postgresql.org
> Subject: Postgresql problem with update double precision
> 
> 
> 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 ?
> 
> --
> Regards,
> Condor

"double precision" is imprecise data type, that's why you see what you see.

If you want to avoid your problem, switch to NUMERIC(precision, scale), which is precise data type.
Alter the type of your "double" columns.

Regards,
Igor Neyman

pgsql-general by date:

Previous
From: "mark"
Date:
Subject: Re: Hot Standby Lag Calculation
Next
From: Tom Lane
Date:
Subject: Re: Temp table visibility