Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TDTXl-0005Zm-Ez for pgsql-jdbc@postgresql.org; Mon, 17 Sep 2012 05:06:49 +0000 Received: from mail-oa0-f46.google.com ([209.85.219.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TDTXj-00080d-N7 for pgsql-jdbc@postgresql.org; Mon, 17 Sep 2012 05:06:48 +0000 Received: by oago6 with SMTP id o6so4372606oag.19 for ; Sun, 16 Sep 2012 22:06:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=/5NAASndgt197aQr28QqFSwERHfeaxg7xHJ3kmW0PYo=; b=UL+2OCGTUvRoDrVb2ZxvnkfpX8JVj2KWTZ/xMDo5eWRG1fojvJmOXSe2LG02BjrAby kSHeWw/2t1iHsWdVrg2pLmrV04ZiS2LxZlH5aTWbuSJKf4jrwQCtg0VammQ+9+vKLEXy HoE0smS60t+8kY0EGcoVjbNVEt1NC0rAqVVmjyr8SkKOpFJHnmQzE+8Y2jgpT3Hn/Gr7 7bHfgTB7/5wUXa7XqH6oD2RqnO8YgXVc4raV99+X0leNU5wY9qqbOl/iXkfYPvKrhIyy 1BUtcAXlL8TZyQXvrtZxs6pJjUHeWXbRutJCn197z4wOSBns9ARpyrMaBFXKQVmKV58D c8eQ== Received: by 10.60.26.41 with SMTP id i9mr9249917oeg.65.1347858405567; Sun, 16 Sep 2012 22:06:45 -0700 (PDT) Received: from ayaki.localdomain (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id k3sm9660839obw.4.2012.09.16.22.06.42 (version=SSLv3 cipher=OTHER); Sun, 16 Sep 2012 22:06:44 -0700 (PDT) Message-ID: <5056AFDF.7040908@ringerc.id.au> Date: Mon, 17 Sep 2012 13:06:39 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: DocSea - Patrice Delorme CC: Kevin Grittner , pgsql-jdbc@postgresql.org Subject: Re: Bug : FAST_NUMBER_FAILED when getting NaN on BigDecimal References: <504F144C.20108@docsea.com> <504F0006020000250004A19B@gw.wicourts.gov> <50504F13.2020607@docsea.com> In-Reply-To: <50504F13.2020607@docsea.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnLeDhJL6DAIofcx96dpx3szztbTYrLcrqIb4WrJPqZ0/b2sasdIiL948y7wIbZsDxlq8D6 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201209/33 X-Sequence-Number: 23269 On 09/12/2012 05:00 PM, DocSea - Patrice Delorme wrote: > You are right, as a matter of Fact BigDecimal does not support NaN like > Double, Float does. Yep. There are some other areas where Java and PostgreSQL don't see eye to eye that result in even more disturbing results. My "favourite" is infinite dates, which PostgreSQL supports but Java does not. They're currently just truncated to Java's biggest date. This means that round-trips through Java can mangle data in new and exciting ways. Particularly fun with ORMs that like to list every column, changed or not, when doing an `UPDATE`. > However, postgres DOES support it and I find it disturbing that the > driver fails so badly without explaination (I had to dig in the driver > source to find out what the problem was). Yeah, that's an issue. How would you expect it to be handled? Preferences/advice? > The problem is that somehow I managed to write my Double NaN to database > but wasn't able to read it back even though I was using the very same > driver in both cases! Yeah, that's not good. I'm honestly not sure what to do about it, though. PgJDBC certainly can't return a Double NaN where it'd normally return BigDecimal. > To me, behaviour is not coherent. Either wriiting of NaN is prevented or > reading is functional ! Agreed, that's nasty. The thing is that NaN *is* supported for Double, so if your column type is float8 it'll all work fine. To prevent Double (NaN) being sent as a value for a numeric column, PgJDBC would need to ask the server for the column type and reject the value only if the target column were numeric. Even then I'm not sure that'd really do the job, as it'd be trivial to accidentally or intentionally get around with functions/casts that take a double argument and produce numeric. > Maybe a more explicit Exception like "numeric NaN values not supported" > and not "org.postgresql.util.PSQLException: Bad value for type > BigDecimal : NaN;" which is rather obscure Certainly some improvement to the message is warranted. I'm not sure I like the proposed one though. Maybe "BigDecimal cannot represent NaN, so the NUMERIC 'NaN' from PostgreSQL could not be returned." ? > or to Extend BigDecimal with PgBigDecimal that supports NaN (and > infinity)... Tempting, but that way may lie madness given the assumptions code tends to make about BigDecimal. I'd be pretty reluctant to do that, though it might prove to be the best answer. -- Craig Ringer