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 3566453CFC for ; Thu, 28 Apr 2005 06:25:34 -0300 (ADT) 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 46546-09 for ; Thu, 28 Apr 2005 09:25:31 +0000 (GMT) Received: from miffy.juergenspecht.com (miffy.juergenspecht.com [69.93.124.90]) by svr1.postgresql.org (Postfix) with ESMTP id 3A36F53CF8 for ; Thu, 28 Apr 2005 06:25:27 -0300 (ADT) Received: from az206.opt2.point.ne.jp ([218.230.104.206] helo=[192.168.1.13]) by miffy.juergenspecht.com with asmtp (Exim 4.34) id 1DR5Gy-0004qx-8J for pgsql-jdbc@postgresql.org; Thu, 28 Apr 2005 05:25:28 -0400 Subject: Re: Array support From: Thomas O'Dowd To: pgsql-jdbc@postgresql.org In-Reply-To: <42681D28.6060408@opencloud.com> References: <1114094185.26958.22.camel@localhost.localdomain> <42681D28.6060408@opencloud.com> Content-Type: text/plain Date: Thu, 28 Apr 2005 18:25:20 +0900 Message-Id: <1114680320.8404.88.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200504/191 X-Sequence-Number: 12798 Thanks for the reply guys. I created a StringArray object which implements the Array interface and overrides toString(). It seems to work well for the moment. I ran into 2 problems with it so far, the 2nd of which I need help with. 1. I tried to use the syntax ARRAY['one'] in the string returned by toString(). This fails with the server error: array value must start with "{" or dimension information So it looks like that format is not supported by server side prepared statements. Next I tried generating the other array syntax {"one"} and this seemed to work well so no problem here for the moment. 2. How do you set an array to null? I tried: PreparedStatement.setNull(index, java.sql.Types.ARRAY); but it throws the exception org.postgresql.util.PSQLException: Unknown Types value. at org.postgresql.jdbc2.AbstractJdbc2Statement.setNull(AbstractJdbc2Statement.java:1003) I think that should work, no? Had a brief look at the code in jdbc2.AbstractJdbc2Statement and indeed it doesn't handle type Array nor does Oid.ARRAY map to anything. I also tried to get my StringArray.toString() method to return the string "NULL", ie: return "NULL", when the string array object that I want to save to the database is null. This fails with the exception. array value must start with "{" or dimension information I also tried return "{}" but this doesn't generate a null in the database as its an empty array. Q: How do I set an array column to null using a PreparedStatement? Just in case it matters, I'm using 8.0.1 and postgresql-8.0-310.jdbc3.jar with jdk1.5.0_02. Tom. On Fri, 2005-04-22 at 09:37 +1200, Oliver Jowett wrote: > Kris Jurka wrote: > > > > On Thu, 21 Apr 2005, Thomas O'Dowd wrote: > > >>PS. I looked at trying to use PreparedStatement.setArray() but it takes > >>an java.sql.Array, which is just an Interface. I guess I could try > >>creating a class that implements Array and try passing that to > >>setArray() but I'm not even sure if that would work yet either. The > >>setObject() way suggested by the spec is definitely simpler. > > > > > > That will work although there are some requirements for getBaseTypeName I > > think, it must return the pg specific type name used. > > More importantly, toString() has to return the data formatted as the > server expects.. > > -O