Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 427FB633773 for ; Mon, 6 Jul 2009 22:04:23 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 72981-09 for ; Mon, 6 Jul 2009 22:04:12 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ns1.officenet.no (unknown [195.159.87.244]) by mail.postgresql.org (Postfix) with ESMTP id 29F34632C2B for ; Mon, 6 Jul 2009 22:04:19 -0300 (ADT) Received: from [77.106.167.81] (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 1MNz6R-00050v-9z for pgsql-jdbc@postgresql.org; Tue, 07 Jul 2009 03:04:16 +0200 From: Andreas Joseph Krogh Organization: OfficeNet AS To: pgsql-jdbc@postgresql.org Subject: Re: Retrieving results from ARRAY and ROW Date: Tue, 7 Jul 2009 03:04:04 +0200 User-Agent: KMail/1.12.0 (Linux/2.6.28-13-generic; KDE/4.2.95; i686; ; ) References: <200907070214.01001.andreak@officenet.no> In-Reply-To: <200907070214.01001.andreak@officenet.no> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <200907070304.04502.andreak@officenet.no> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.1 tagged_above=0 required=5 tests=RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200907/14 X-Sequence-Number: 19782 On Tuesday 07 July 2009 02:14:00 am Andreas Joseph Krogh wrote: > Hi all! >=20 > (Using pg-8.4 with postgresql-8.4-701.jdbc4.jar) > I have the following (simplified for example) schema: >=20 > CREATE TABLE person(id INTEGER, name VARCHAR); > INSERT INTO person(id, name)=20 > VALUES (1,'James'),(2, 'Jack'); > CREATE TABLE person_dep(person_id INTEGER, dep VARCHAR); > INSERT INTO person_dep(person_id, dep)=20 > VALUES (1,'Dep1'),(1,'Dep2'); >=20 > SELECT p.id, p.name > , ARRAY(SELECT ROW(dep.person_id, dep.dep) > FROM person_dep dep > WHERE dep.person_id =3D p.id) AS my_array > FROM person p > WHERE p.id IN (1,2); >=20 > id | name | my_array > ----+-------+------------------------- > 1 | James | {"(1,Dep1)","(1,Dep2)"} > 2 | Jack | {} > (2 rows) >=20 > The problem is that I'm not able to retrieve the results from "my_array" = using rs.getArray("my_array").getArray(), which results in: > org.postgresql.util.PSQLException: Method org.postgresql.jdbc4.Jdbc4Array= =2EgetArrayImpl(long,int,Map) is not yet implemented. >=20 > Does someone know any better way to write this query which makes it work = with JDBC? I know I can write 2 sub-selects instead of one and have each co= lumn return and array of integer[] and varchar[], but I'm trying to avoid h= aving more than *one* sub-select. >=20 > My actual query involves a "WITH RECURSIVE" sub-select which retrieves pairs for the parent of each node to form a path up to the top-most= parent, which makes several sub-selects involving CTE unattractive. Replying to my self... I found this post to return a dataset similar to what I'm having: http://merlinmoncure.blogspot.com/2007/09/this-will-be-first-in-what-hopefu= lly-be.html id | array_accum=20 =2D---+----------------------------- 1 | {"(abc,data)","(ghi,data)"} 2 | {"(def,data)","(jlk,data)"} The question remains: How do I get arrays of composite types (ROW) in a typ= e-safe way in my application using JDBC? =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-----------------------+---------------------------------------------+