X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (mx2.hub.org [200.46.204.254]) by postgresql.org (Postfix) with ESMTP id 8BA4911F6D1E for ; Thu, 13 Apr 2006 21:07:34 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: -1.18 X-Spam-Level: X-Spam-Status: No, score=-1.18 required=5 tests=[AWL=1.419, BAYES_00=-2.599] Received: from postgresql.org ([200.46.204.71]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id 9KSEtulv+h26 for ; Thu, 13 Apr 2006 21:07:33 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail63.csoft.net (mail63.csoft.net [205.205.214.4]) by postgresql.org (Postfix) with SMTP id 0EE4E11F6CCE for ; Thu, 13 Apr 2006 21:07:30 -0300 (ADT) Received: (qmail 15112 invoked by uid 1112); 14 Apr 2006 00:07:30 -0000 Date: Thu, 13 Apr 2006 19:07:30 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary2.csoft.net To: Jeff Hubbach cc: pgsql-jdbc@postgresql.org Subject: Re: Possible regression: setNull() usage changed from 7.4 to In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Archive-Number: 200604/102 X-Sequence-Number: 15036 On Thu, 13 Apr 2006, Jeff Hubbach wrote: > In the process of upgrading an app, I came across a change in behavior > of PreparedStatement.setNull(). The behavior of the driver for 7.3 and > 7.4 is consistent, a call to: > stmt.setNull(1,java.sql.Types.NULL); > succeeds. However, in 8.0 and up (including the 8.2 dev driver), this > call fails with a "Could not determine data type" error. > > PreparedStatement st = conn.prepareStatement("select count(*) from > test_null where ? is null"); > st.setNull(1,java.sql.Types.NULL); // Fails > //st.setNull(1,java.sql.Types.INTEGER); // Works > This is an expected change when the driver was modified to use server side prepared statements instead of just interpolating text values into the query string. When given a null value, the driver cannot try to infer any type information about it and must let the server determine what the type is. Your example is a situation where the server cannot possible do so. If you had written "WHERE intcol = ?", then it could infer that the parameter should be an integer. For a situation like "? is null" you must provide the server with the parameter type (integer is a real type, Types.NULL, Types.OTHER are not). The driver cannot pick an arbitrary type because if the server infers a different type then an appropriate cast must exist or the query will bail out. The server generally does a reasonable job of inferring types, the example you've shown is an awfully contrived one, why would you need the server to tell you if a value was null? Kris Jurka