X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6123D3A562B for ; Mon, 24 Jan 2005 20:17:38 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 95013-03 for ; Mon, 24 Jan 2005 20:17:21 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 4ACA33A4EA1 for ; Mon, 24 Jan 2005 20:17:21 +0000 (GMT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1CtAeD-0006t6-00; Tue, 25 Jan 2005 09:17:17 +1300 Message-ID: <41F557C8.6030805@opencloud.com> Date: Tue, 25 Jan 2005 09:17:12 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0 (X11/20041228) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jean-Pierre Pelletier Cc: pgsql-jdbc@postgresql.org, Jean-Pierre Pelletier Subject: Re: setObject on PGInterval throws "Unknown Type null" References: In-Reply-To: X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/236 X-Sequence-Number: 12116 Jean-Pierre Pelletier wrote: > if myPgInterval != null > Originally code: myPreparedStatement.setObject(i, myPGInterval) > It throws SQLException "Unknown type null" That's a bug; the PGInterval(String) constructor is broken. As a workaround try this: PGInterval value = new PGInterval(); value.setValue("1 day"); I will fix this in CVS shortly. Thanks for the report! > We tried: myPreparedStatement.setObject(i,myPGInterval,Types.OTHER) > It throws "setNull(i, Types.OTHER) is not supported; use > setObject(i,null, Types.OTHER) instead" > > How should setObject be coded with a PGInterval ? For extension types, you need to jump through some hoops to identify the actual postgresql type in use, since a simple Types value isn't sufficient. Try this to set a null: myPreparedStatement.setObject(i, new PGInterval()); (the default ctor constructs an interval-typed "null" value, similar to "null::interval" in plain SQL) I'll try to cram that into a more useful exception message.. > With JDBC Build 309, setObject requires an SQL Type when object == null, > this makes setObject(i, object) useless. Hardly useless; it works in every non-null case. > Why do JDBC requires an SQL Type when the same statement can be > processed by psql > without the SQL type specified? The short answer: because JDBC is strongly typed while psql knows nothing at all about parameter types. There was extended discussion about this on the list at the time. See: http://archives.postgresql.org/pgsql-jdbc/2004-10/msg00059.php I have an outstanding query with the JDBC expert group about clarifying this case. The JDBC API goes to some trouble to provide type information for every parameter even when nulls are involved (see, for example, setNull). setObject(i,null) seems like an oversight. > Is it supported by other DBMS? I don't know -- is it? I can think of one (Clustra, subsequently bought by Sun) that would break horribly if you tried something like this. -O