Search Postgresql Archives

Casting numeric values to double

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 +++

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux