Skip site navigation (1) Skip section navigation (2)

JDBC driver doesn't handle NaN values

From: Jonathan Purvis <jon(at)reeltwo(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: JDBC driver doesn't handle NaN values
Date: 2004-01-09 03:01:34
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugspgsql-jdbc
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 
file.  There may need to be other files changed (eg in the jdbc2 or 
jdbc3 directories), but i don't know where.

< 		bind(parameterIndex, Float.toString(x), PG_FLOAT);
 > 		String value = Float.isNaN(x) ? "'NaN'" : Float.toString(x);
 > 		bind(parameterIndex, value, PG_FLOAT);
< 		bind(parameterIndex, Double.toString(x), PG_DOUBLE);
 > 		String value = Double.isNaN(x) ? "'NaN'" : Double.toString(x);
 > 		bind(parameterIndex, value, PG_DOUBLE);
 > 		else if (x instanceof Float)
 > 			return ((Float) x).isNaN() ? "'NaN'" : x.toString();
 > 		else if (x instanceof Double)
 > 			return ((Double) x).isNaN() ? "'NaN'" : x.toString();
< 				 x instanceof Double || x instanceof Short ||
< 				 x instanceof Number || x instanceof Float)
 > 				 x instanceof Number || x instanceof Short)




pgsql-bugs by date

Next:From: Denis N. StepanovDate: 2004-01-09 06:10:46
Subject: Re: BUG #1044: snprintf() shipped with PostgreSQL is not
Previous:From: Tom LaneDate: 2004-01-09 02:22:33
Subject: Re: BUG #1045: hostname lookup in psql or does work

pgsql-jdbc by date

Next:From: Antonio GallardoDate: 2004-01-09 05:18:39
Subject: [BUG] - Invalid UNICODE character sequence found (0xc000)
Previous:From: Oliver JowettDate: 2004-01-08 22:56:25
Subject: Re: PreparedStatement parameters and mutable objects

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group