Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D82FC6350AB for ; Tue, 9 Mar 2010 19:55:52 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 16708-02 for ; Tue, 9 Mar 2010 23:55:35 +0000 (UTC) X-Greylist: delayed 00:16:06.878071 by SQLgrey-1.7.6 Received: from ns1.officenet.no (unknown [195.159.87.244]) by mail.postgresql.org (Postfix) with ESMTP id D2C4C633A71 for ; Tue, 9 Mar 2010 19:55:41 -0400 (AST) Received: from [95.34.25.88] (helo=andreak-laptop.localnet) by ns1.officenet.no with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1Np91K-00066p-5g for pgsql-jdbc@postgresql.org; Wed, 10 Mar 2010 00:39:31 +0100 From: Andreas Joseph Krogh Organization: OfficeNet AS To: pgsql-jdbc@postgresql.org Subject: Retrieving multidimentional array-column using JDBC Date: Wed, 10 Mar 2010 00:39:14 +0100 User-Agent: KMail/1.13.1 (Linux/2.6.31-20-generic; KDE/4.4.1; i686; ; ) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201003100039.14562.andreak@officenet.no> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.804 tagged_above=-10 required=5 tests=AWL=-0.794, BAYES_05=-1.11, RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 201003/27 X-Sequence-Number: 20367 Hi all. I have a query which returns a multidimentional array (2D) of varchar and I= 'm having problems retrieving the results using JDBC. =46irst, since PG doesn't support arrays of arrays, I've created a custom t= ype: create type text_array as (c TEXT[]); Then I have the following schema: =2D-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D8<=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D CREATE TABLE foo( id integer primary key ); CREATE TABLE pathway( id integer primary key, p_id integer references pathway(id), element varchar ); CREATE TABLE path_usage( foo_id integer references foo(id), pathway_id integer references pathway(id) ); INSERT INTO foo VALUES(1); insert into pathway(id, p_id, element) values(1, null, 'path'); insert into pathway(id, p_id, element) values(2, 1, 'to'); insert into pathway(id, p_id, element) values(3, 2, 'first'); insert into pathway(id, p_id, element) values(4, 2, 'second'); insert into path_usage(foo_id, pathway_id) values(1, 3); insert into path_usage(foo_id, pathway_id) values(1, 4); =2D-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D8<=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D I use this query to retrieve a list of all "foo"s with their (complete) pat= hs: SELECT act.id, (SELECT array_agg(row(pathway_array)::text_array) FROM (SELECT ARRAY( WITH RECURSIVE parent(level, id, p_id, element) AS( SELECT 1, pw.id, pw.p_id, pw.element UNION ALL SELECT rec.level + 1, pw_.id, pw_.p_id, pw_.element=20 FROM pathway pw_, parent rec WHERE pw_.id =3D rec.p_id ) SELECT element FROM parent ORDER BY level DESC ) AS pathway_array FROM pathway pw, path_usage pu WHERE pu.foo_id =3D act.id AND pu.pathway_id =3D pw.id ORDER BY lower(pw.element) ASC ) x ) AS pathway_array =46ROM foo act ; This returns: id | pathway_array =2D---+---------------------------------------------------- 1 | {"(\"{path,to,first}\")","(\"{path,to,second}\")"} (1 row) No, so far all good, *but*, I now want to retrieve this "pathway_array" col= umn using JDBC and getArray(). My code looks like: Array qArray =3D rs.getArray("pathway_array"); Object o =3D qArray.getArray(); throws Exception: =2E.. =2E.. Caused by: org.postgresql.util.PSQLException: Method org.postgresql.jdbc4.J= dbc4Array.getArrayImpl(long,int,Map) is not yet implemented. at org.postgresql.Driver.notImplemented(Driver.java:753) So - does anyone know how to retrieve such arrays using JDBC? Anyone knows if there's another way of retrieving the array of arrays witho= ut using the "array_agg trick" using a custom-type? =2D-=20 Andreas Joseph Krogh Senior Software Developer / CTO =2D-----------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Rosenholmveien 25 | know how to do a thing and to watch | 1414 Troll=C3=A5sen | somebody else doing it wrong, without | NORWAY | comment. | | | Tlf: +47 24 15 38 90 | | =46ax: +47 24 15 38 91 | | Mobile: +47 909 56 963 | | =2D-----------------------+---------------------------------------------+