Cast problem with arrays

1234
2012-04-25
2014-01-19
  • 1234
    1234
    2012-04-25

    Was trying to simplify by putting a field which was a separate table as an ARRAY column of another table.  Was building in line update statements.  The data type of the field was FLOAT.  I got occasional ClassCastExceptions.  Here is a test example using INSERTs instead:

    CREATE TABLE A (
    dbl DOUBLE ARRAY[10],
    flt FLOAT ARRAY[10]
    );
    // these combinations work
    INSERT INTO A VALUES(ARRAY[123.4], ARRAY[123.4]);
    INSERT INTO A VALUES(ARRAY[1.0318572E7], ARRAY[123.4]);
    INSERT INTO A VALUES(ARRAY[123.4], ARRAY[1.0318572E7]); 
    INSERT INTO A VALUES(ARRAY[123.4], ARRAY[1031857200.0])
    // both of these fail with: .SQLTransactionRollbackException: ClassCastException: BigDecimal cannot be cast to Double
    INSERT INTO A VALUES(ARRAY[1.0318572E7, 123.4], ARRAY[1234.4]); 
    INSERT INTO A VALUES(ARRAY[123.4], ARRAY[1.0318572E7, 1234.4]);
    

    I might be able to format the input without scientific notation, but thought you should know.  Right now just using String concatenation to build the statements.  Some kind of simpleformat should work, looking at the last working INSERT.

     
  • 1234
    1234
    2012-04-25

    FYI, switched to:
    static java.text.DecimalFormat FLOAT_FORMATTER = new java.text.DecimalFormat("##########.0######");

    and called FLOAT_FORMATTER.format(array_).

    workaround successful, assuming not exceeding the size shown on either side of decimal
    _

     
  • Fred Toussi
    Fred Toussi
    2012-04-25

    Thanks.

    Fixed for the next snapshot and release versions.