Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 500F19FB1DD for ; Fri, 2 Feb 2007 03:08:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 19847-03 for ; Fri, 2 Feb 2007 03:07:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail63.csoft.net (mail63.csoft.net [205.205.214.4]) by postgresql.org (Postfix) with ESMTP id 016439FA311 for ; Fri, 2 Feb 2007 03:07:44 -0400 (AST) Received: by mail63.csoft.net (Postfix, from userid 1112) id E5BB9FB2F; Fri, 2 Feb 2007 02:07:43 -0500 (EST) Date: Fri, 2 Feb 2007 02:07:43 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary2.csoft.net To: =?ISO-8859-2?Q?Miroslav_=A9ulc?= cc: pgsql-jdbc@postgresql.org Subject: Re: JDBC and arrays In-Reply-To: <45C295F4.4030100@startnet.cz> Message-ID: References: <45C295F4.4030100@startnet.cz> MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 Content-Type: TEXT/PLAIN; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE X-Archive-Number: 200702/13 X-Sequence-Number: 16569 On Fri, 2 Feb 2007, Miroslav =A9ulc wrote: > I tried to find some info on how to work with arrays using PostgreSQL JDB= C=20 > driver but didn't find anything useful except that I can implement=20 > java.sql.Array to get support for arrays. Can someone, please, send me a = link=20 > on how to write and read array data using PostgreSQL JDBC driver or give = me a=20 > brief explanation? I'm also interested how to work with inet[] arrays as = they=20 > do not seem to be directly supported by JDBC API. Reading arrays is pretty straightforward: ResultSet rs =3D stmt.executeQuery("SELECT '{a,b}'::text[]"); rs.next(); Array arr =3D rs.getArray(1); String s[] =3D (String)arr.getArray(); Writing arrays is not easy because prior to the JDBC4 spec there was no=20 way to create java.sql.Array objects without creating a class that=20 implements java.sql.Array yourself. Now JDBC4 offers=20 Connection.createArrayOf() which unfortunately we haven't implemented yet.= =20 So while there is a light at the end of the tunnel you're still stuck=20 implementing java.sql.Array yourself. Check the mailing list for examples= =20 of that. Currently arrays of non-standard datatypes like inet are not supported.=20 Seems possible to do if you were willing to use PGobject for unknown=20 types, but no one has done it. Also more complicated things like multi-dimensional arrays are note=20 supported. Kris Jurka=