pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Broersma Jr <rabroersma@yahoo.com>
To: Dave Cramer <pg@fastcrypt.com>
To: Chris Stuhr <cstuhr@ephibian.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Null bind variable in where clause
Date: Tue, 1 May 2007 04:55:10 -0700 (PDT)
Message-ID: <125886.83155.qm@web31806.mail.mud.yahoo.com> (raw)
In-Reply-To: <4906DD3E-322A-4E26-8600-B967AFA8A58F@fastcrypt.com>

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 <pg@fastcrypt.com> 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
> 




view thread (6+ messages)  latest in thread

Message-ID: <125886.83155.qm@web31806.mail.mud.yahoo.com>
Permalink:  ../125886.83155.qm@web31806.mail.mud.yahoo.com/
Also on:    postgresql.org/message-id/125886.83155.qm@web31806.mail.mud.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: rabroersma@yahoo.com, pg@fastcrypt.com, cstuhr@ephibian.com
  Subject: Re: Null bind variable in where clause
  In-Reply-To: <125886.83155.qm@web31806.mail.mud.yahoo.com>
  References: <4906DD3E-322A-4E26-8600-B967AFA8A58F@fastcrypt.com> <125886.83155.qm@web31806.mail.mud.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox