From: | Mike Finn <mike(dot)finn(at)tacticalExecutive(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Comparing fixed precision to floating |
Date: | 2001-08-21 21:41:22 |
Message-ID: | 01082115412200.29245@birch.tacticalExecutive.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-jdbc |
I am using numeric(p,s) fields in a database schema.
Using queries that contain a comparison like
...
where numericField = 456.789
....
will generate an error
Unable to identify an operator '=' for types 'numeric' and 'float8'
You will have to retype this query using an explicit cast
and if i explicitly cast the 456.789 (456.789::numeric) it does in fact work.
But how do we get around this error when using JDBC?
Shouldn't =(numeric, float8) be a standard operator in postgresql?
My query is a dynamically prepared statement in java where many of the
constant values are user supplied and poped into the statement via
pstmt.setObject(pos, valueObj, type)
in the case of a numeric field the "type" parameter is Types.NUMERIC and the
"valueObj" parameter is a java.math.BigDecimal. (java.math.BigDecimal is the
only way I know of to represent fixed precision and scale number in java).
And of course this will blow with the previous error.
I do have a work around which is to force the user supplied constant (a
BigDecimal) to a string and user pstmt.setString(...). Effectively this
create a clause of the form
...
where numericField = '456.789'
....
but it postgres will automatically cast the right hand side to a numeric I
would have expected it to be able to cast a float8 constant to a numeric as
well.
If there is good reason why this can't be done, could someone explain what I
am missing. Else could we put a =(numeric, float8) operator on the todo list?
Thanks, in advance for any help.
Mike.
===================
Mike Finn
Tactical Executive Systems
mike(dot)finn(at)tacticalExecutive(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-08-21 22:28:33 | Re: Postgres hangs during VACUUM (autocommit = false) |
Previous Message | Mitch Vincent | 2001-08-21 21:34:32 | Re: Data types |
From | Date | Subject | |
---|---|---|---|
Next Message | Gunnar Rønning | 2001-08-21 23:44:06 | Re: Couple of patches for jdbc driver |
Previous Message | Ned Wolpert | 2001-08-21 21:37:05 | Re: JDBC changes for 7.2... some questions... |