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

Reply via email to