Problem with java infinity mapping to postgres real column type - Mailing list pgsql-jdbc

From Johan Miller
Subject Problem with java infinity mapping to postgres real column type
Date
Msg-id 3713c3aa0807142254p72e8416dsd8c18a5ebf101212@mail.gmail.com
Whole thread Raw
Responses Re: Problem with java infinity mapping to postgres real column type
List pgsql-jdbc
Hi,

I have searched the mail archives at the postgres site but have not come up with anything that addresses this particular issue.
I have found that when trying to insert a Java Float.POSITIVE_INFINITY or its negative counterpart into a database column with data type real using a jdbc driver 8.1-406 or 8.2-504 postgres will throw an overflow error.
Since both Java and Postgres real data type support infinity then this seems very strange.

After some testing I found that the situation described above does not throw an error using a jdbc driver 8.0-310. After some more debugging it seems that this is caused by the Oid type being used for float input. The 8.0 driver uses Oid.FLOAT4 but the 8.1 and 8.2 drivers both use Oid.FLOAT8 (AbstractJdbc2Statement.java setFloat()). I also found that it is possible to insert inifinity into a column with data type real if the setObject function is used with the targetSqlType being REAL since this data type uses Oid.FLOAT4.

What would be the best practice in this situation?
This did not seem a problem when using the double precision column data type. Althouh it seems a little extreme to have to convert a column data type to accomodate a few values that can not be inserted correctly. How much would a tables size increase if a real data type is converted to a double precision?

--
Johan Miller

pgsql-jdbc by date:

Previous
From: quintesse
Date:
Subject: And once again getGeneratedKeys()
Next
From: nalini
Date:
Subject: Transaction handling through java