dbTalk Databases Forums  

[BUGS] JDBC driver doesn't handle NaN values

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] JDBC driver doesn't handle NaN values in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jonathan Purvis
 
Posts: n/a

Default [BUGS] JDBC driver doesn't handle NaN values - 01-08-2004 , 09:15 PM






The JDBC driver that ships with PostgreSQL 7.4.1 doesn't insert floats
of value NaN. As it uses Float.toString(x) to convert the value for
insertion into the database, it tries to insert NaN instead of 'NaN' and
gets the error "Attribute 'nan' not found". The same bug occurs for
doubles and will probably occur for infinite values as well (i haven't
tested it). This bug also exists in 7.2.4 and in the 7.2.1 version
currently in Debian stable.


Here is a patch for the
"src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java"
file. There may need to be other files changed (eg in the jdbc2 or
jdbc3 directories), but i don't know where.


1062c1062,1063
< bind(parameterIndex, Float.toString(x), PG_FLOAT);
---
Quote:
String value = Float.isNaN(x) ? "'NaN'" : Float.toString(x);
bind(parameterIndex, value, PG_FLOAT);
1075c1076,1077
< bind(parameterIndex, Double.toString(x), PG_DOUBLE);
---
Quote:
String value = Double.isNaN(x) ? "'NaN'" : Double.toString(x);
bind(parameterIndex, value, PG_DOUBLE);
1553a1556,1559
else if (x instanceof Float)
return ((Float) x).isNaN() ? "'NaN'" : x.toString();
else if (x instanceof Double)
return ((Double) x).isNaN() ? "'NaN'" : x.toString();
1555,1556c1561
< x instanceof Double || x instanceof Short ||
< x instanceof Number || x instanceof Float)
---
Quote:
x instanceof Number || x instanceof Short)


Regards,

Jon

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.