Casting numeric values to double - Mailing list pgsql-general

From Daniel Schregenberger
Subject Casting numeric values to double
Date
Msg-id 7856.1128346302@www18.gmx.net
Whole thread Raw
Responses Re: Casting numeric values to double  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Casting numeric values to double  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Hi,

I recently stumbled uppon the following thing:
If I compare a field of type "numeric" to a small decimal constant like
"3.6", the constant is interpreted as a "double precision" value and the
comparison fails with the following message:

# SELECT * FROM tr_table_okpx WHERE prating >= 3.6;

Unable to identify an operator '>=' for types 'double precision' and
'numeric'
        You will have to retype this query using an explicit cast

I then changed the field to be of type "double precision". Now if I compare
it to a constant with more than 15 decimal digits (like
"3.5999999999999996"), the constant is interpreted as numeric value and the
comparison fails again.

# SELECT * FROM tr_table_okpx WHERE prating >= 3.5999999999999996;

Unable to identify an operator '>=' for types 'double precision' and
'numeric'
        You will have to retype this query using an explicit cast

This is a little annoying, as I am generating my queries in Java where
double values can easily take more than 15 digits.
I'm using Postgre 7.2, which might be a bit outdated but I could not find
any information whether this behaviour has changed in newer versions. So
before I try to upgrade I'd like to ask if upgrading will help or if the
recommended way to handle this is really cast all constants:

# SELECT * FROM tr_table_okpx WHERE prating >= 3.5999999999999996::double
precision;

Any help appreciated.

-- Daniel

--
http://www.despite.ch/ -- http://www.npfdd.ch/

5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse f�r Mail, Message, More +++

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Limitations of PostgreSQL
Next
From: Ben-Nes Yonatan
Date:
Subject: Re: Broken pipe