Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 8767B9FB779 for ; Tue, 1 May 2007 08:55:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 28216-09 for ; Tue, 1 May 2007 08:55:05 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from web31806.mail.mud.yahoo.com (web31806.mail.mud.yahoo.com [68.142.207.69]) by postgresql.org (Postfix) with SMTP id 2C8249FB4E4 for ; Tue, 1 May 2007 08:55:15 -0300 (ADT) Received: (qmail 34719 invoked by uid 60001); 1 May 2007 11:55:10 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=Xj+n6jIIRC4iRNMrGjpP+JHLSTljfsY7SxnG2fj9AwjHi6i3W0sI1zcghz/pfco1jl2yP70ZdWz9hh5YhRjtn/dZSYlVITnSY4P4ki2c+wKl75JmEsXb1d059LKvuBcf7P0+TpiIYGCfShgiOBgRgG7e/VYOE6yJB1VuzsJU76A=; X-YMail-OSG: BkDNF9gVM1llPr4T7OeX79rknf79Lh.2NF1KAihpCz9ytIhC0drWBwFEqhQd8.QQyn8h6l4DknyTyRUuun2ts5.FIXmUXGWxLIr1brXYvUbo72O8lF8xKZ93lOjyHoQ9xKKKY8cjXCkPBXULAwijrtgVo8z6pzA- Received: from [75.84.89.248] by web31806.mail.mud.yahoo.com via HTTP; Tue, 01 May 2007 04:55:10 PDT Date: Tue, 1 May 2007 04:55:10 -0700 (PDT) From: Richard Broersma Jr Subject: Re: Null bind variable in where clause To: Dave Cramer , Chris Stuhr Cc: pgsql-jdbc@postgresql.org In-Reply-To: <4906DD3E-322A-4E26-8600-B967AFA8A58F@fastcrypt.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <125886.83155.qm@web31806.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.768 tagged_above=0 required=5 tests=AWL=0.012, BAYES_00=-2.599, DNS_FROM_RFC_ABUSE=0.2, DNS_FROM_RFC_POST=1.708, DNS_FROM_RFC_WHOIS=1.447 X-Spam-Level: X-Archive-Number: 200705/2 X-Sequence-Number: 16992 I am just a beginner at JDBC, but another why to achieve this it to rewrite your query this way: > > "UPDATE t SET a = ? WHERE b = ?"; becomes: UPDATE T SET a = ? WHERE ( b = ? ) IS KNOWN OR ( b = ? ) IS UNKNOWN; or you can get the same effect by: UPDATE T SET a = ? WHERE b = ? OR b IS NULL; looks like the second way is probably better. --- Dave Cramer wrote: > This is a server issue. > > If you really want this behaviour then > > set > transform_null_equals = off to on > > in postgresql.conf > > > Dave > On 30-Apr-07, at 9:34 PM, Chris Stuhr wrote: > > > It looks like you can not use a bind variable when trying to match > > null in a where clause. Is there any way to get the desired effect > > without having to remove the bind variable and rewrite the query to > > "WHERE b IS null"? > > > > import java.sql.*; > > > > public class a { > > > > public static void main(String args[]) throws Exception { > > String sql = "CREATE TABLE t(a int, b int)"; > > Class.forName("org.postgresql.Driver"); > > Connection conn = DriverManager.getConnection( > > "jdbc:postgresql://10.20.1.70:5432/firm", "gaiam", ""); > > try { > > Statement stmt = conn.createStatement(); > > stmt.executeUpdate(sql); > > sql = "INSERT INTO t(a,b) VALUES (3,null)"; > > stmt.executeUpdate(sql); > > stmt.close(); > > } catch (SQLException sqle) { > > sqle.printStackTrace(); > > } > > > > sql = "UPDATE t SET a = ? WHERE b = ?"; > > PreparedStatement pstmt = conn.prepareStatement(sql); > > pstmt.setInt(1, 4); > > pstmt.setObject(2, null); > > int x = pstmt.executeUpdate(); > > System.out.println(x); > > pstmt.close(); > > Statement stmt = conn.createStatement(); > > stmt.executeUpdate("DROP TABLE t"); > > stmt.close(); > > conn.close(); > > } > > } > > > > Will print 0 instead of 1 > > > > -Chris > > > > > > ---------------------------(end of > > broadcast)--------------------------- > > TIP 3: Have you checked our extensive FAQ? > > > > http://www.postgresql.org/docs/faq > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: You can help support the PostgreSQL project by donating at > > http://www.postgresql.org/about/donate >