Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 3C187A87FB0 for ; Wed, 30 Nov 2011 03:36:18 -0400 (AST) Received: from cloudburst.actrix.co.nz ([203.96.16.181]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RVeiD-00023m-Rc for pgsql-jdbc@postgresql.org; Wed, 30 Nov 2011 07:36:17 +0000 Received: from localhost (202-154-129-242.ras-dynamic.connections.net.nz [202.154.129.242]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by cloudburst.actrix.co.nz (Postfix) with SMTP id AF89DA500; Wed, 30 Nov 2011 20:35:57 +1300 (NZDT) From: bht@actrix.gen.nz To: Oliver Jowett Cc: pgsql-jdbc@postgresql.org Subject: Re: Bug: Cannot pass null in Parameter in Query for ISNULL Date: Wed, 30 Nov 2011 20:36:02 +1300 Message-ID: References: <6ekbd7dm4d6su5b9i4hsf92ibv4j76n51f@4ax.com> In-Reply-To: X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Antivirus: avast! (VPS 111129-2, 30/11/2011), Outbound message X-Antivirus-Status: Clean X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201111/115 X-Sequence-Number: 22450 Hi Oliver, Your response is not entirely unexpected however perplexing in light of the fact that other JDBC drivers don't have this bug. I have tested them. You are basically describing to me the nature of the bug from the perspective of the driver's internals. We can really only be interested in the resolution of it not in a workaround. That is because I had already included the workaround in my testcase posted to the mailing list - for illustration purposes. The reason for not being able to use workarounds is that we are using JPA which is a layer that is not accessible for modification. It would be nice if you could take on board the obvious fact that it is nonsense to test for the "type" of null that - 1) is only used in a parameter 2) the database does not have a problem processing natively 3) is correctly coded with ISNULL. Don't you think that it would be worth the trouble spending some extra driver coding, to detect and allow this scenario and pass the perfectly valid and correct query to the database? Kind Regards, Bernard On Wed, 30 Nov 2011 20:04:43 +1300, you wrote: >> Hi, >> >> Native PostgreSQL has no problem with queries like: >> >> select id from author a where null is null or a.name =3D null >> >> However the JDBC driver fails to process such a query with a >> parameter: >> >> ERROR: could not determine data type of parameter $1 >This is specific to calling PreparedStatement.setObject(index, null). >There is no type information provided when you call that, so it's not >entirely surprising you can get that error. >(Try a native PREPARE with a parameter type of "unknown" and you'll >see the same thing - it's not only JDBC) > This is specific to calling PreparedStatement.setObject(index, null). > To avoid this, use one of these instead: > > =A0* PreparedStatement.setObject(index, null, type) > =A0* PreparedStatement.set(index, null) > =A0* PreparedStatement.setNull(index, type) > > all of which provide type information that the driver needs. >I'd also refer you to the JDBC javadoc for setObject(int,Object) which = says: >=3D=3D >Note: Not all databases allow for a non-typed Null to be sent to the >backend. For maximum portability, the setNull or the setObject(int >parameterIndex, Object x, int sqlType) method should be used instead >of setObject(int parameterIndex, Object x). >=3D=3D >Oliver