db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Thornton <mthorn...@optrak.co.uk>
Subject Re: Double.NaN in table?
Date Wed, 19 Dec 2007 16:31:23 GMT
Daniel John Debrunner wrote:
> David wrote:
>>  For an application I am writing I need to store doubles in a table. 
>> I thought I could use the DOUBLE type when creating the columns in my 
>> tables. Unfortunately the insert fails when the value of the double 
>> is Double.NaN. We use NaN a lot in our analysis. Is there a way to 
>> make this work, or should we just convert everything to a string?
>> Any ideas?
> One possible alternative is to use a BIGINT column.
> Use the java method Double.doubleToLongBits() when storing the value 
> in the database, e.g.
>     double myDouble = ...;
>     ps.setLong(1, Double.doubleToLongBits(myDouble));
> and Double.longBitsToDouble() when reading values, e.g.
>    double myDouble = Double.longBitsToDouble(rs.getLong(1));
> I haven't tried this, and you should probably read the descriptions 
> for those methods, they have some detailed info on Nans. There is also 
> the doubleToRawLongBits() method that could be used.
> No idea on how indexing on the BIGINT column would work with this 
> approach, ie. if the index order would be useful.
> HTH,
> Dan.
It works in terms of storing the data, and I think the index order is 
reasonable. However the semantic meaning of the field is lost from the 
SQL perspective.

Mark Thornton

View raw message