Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 320CAF5C18C for ; Sat, 12 May 2012 17:35:06 -0300 (ADT) Received: from smtp4.clear.net.nz ([203.97.37.64]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1STJ1s-0005ch-Q8 for pgsql-jdbc@postgresql.org; Sat, 12 May 2012 20:35:05 +0000 Received: from mxin2-orange.clear.net.nz (lb2-srcnat.clear.net.nz [203.97.32.237]) by smtp4.clear.net.nz (CLEAR Net Mail) with ESMTP id <0M3X00ENJFU2TF20@smtp4.clear.net.nz> for pgsql-jdbc@postgresql.org; Sun, 13 May 2012 08:34:51 +1200 (NZST) Received: from 203-96-144-189.cable.paradise.net.nz (HELO localhost) ([203.96.144.189]) by smtpin2.clear.net.nz with SMTP; Sun, 13 May 2012 08:34:50 +1200 Date: Sun, 13 May 2012 08:34:49 +1200 From: Bernard Subject: Re: Fwd: Cannot pass null in Parameter in Query for ISNULL In-reply-to: <6364.1336835181@sss.pgh.pa.us> To: PG-JDBC Mailing List Cc: Tom Lane , Maciek Sakrejda Message-id: MIME-version: 1.0 X-Mailer: Forte Agent 1.93/32.576 English (American) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: quoted-printable X-Antivirus: avast! (VPS 120512-0, 12/05/2012), Outbound message X-Antivirus-Status: Clean References: <6364.1336835181@sss.pgh.pa.us> X-Pg-Spam-Score: -0.9 (/) X-Archive-Number: 201205/28 X-Sequence-Number: 22928 SELECT ID, NAME, region_id FROM CUSTOMERORDER WHERE ((? IS NULL) OR (region_id =3D ?)) Based on boolean algebra, the engine query planner can simply eliminate the entire WHERE clause if the parameter is in fact null. I should say that the "?" refers in both instances to the same parameter. So the JDBC driver would only need to allow this to happen. In the case of null being passed to it, the type of null parameters would never matter. In this SQL statement, "(? IS NULL) OR ..." is coded for the purpose of allowing this to happen smoothly. I have verified the positive result with all other database engines/drivers and so I am confident there must be a definite way forward - it is just the question of how we get this done. As long as possible answers look less promising, I obviously have to assume that there is a misunderstanding somewhere. Kind Regards, Bernard On Sat, 12 May 2012 11:06:21 -0400, you wrote: >Bernard writes: >> May I ask for suggestions for a way forward towards a solution? > >The long and the short of this is that your application, which >presumably knows what it might pass for this parameter, has to provide >that type information (by means of using the appropriate setXXX call). >If the server's parser tries to guess a type, that will simply move the >pain from this case to other cases, namely those where the choice really >matters and it guesses wrong. Similarly, the JDBC driver doesn't have >enough information to make a correct guess. > >Having said that, it's interesting to wonder how much would break if >setObject were to arbitrarily assume the data type is TEXT. The >response to anybody complaining would be more or less what I'm saying >to you, which is "don't use setObject if you don't like the results". >Again, this would only be shifting the pain from some cases to others, >but I wonder whether there would be more or fewer pain cases. > > regards, tom lane