Casting numeric values to double

From: "Daniel Schregenberger" <npfdd(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Casting numeric values to double
Date: 2005-10-03 13:31:42
Message-ID: 7856.1128346302@www18.gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 fr Mail, Message, More +++

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ben-Nes Yonatan 2005-10-03 14:21:38 Re: Broken pipe
Previous Message Aman Tur 2005-10-03 13:18:03 Connecting form Access or VB6 to PostgreSQL 8