Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 541622E2DC4 for ; Sun, 23 Dec 2007 19:03:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 66384-08 for ; Sun, 23 Dec 2007 19:02:53 -0400 (AST) Received: from 208091.vserver.de (nirs.de [62.75.208.91]) by postgresql.org (Postfix) with ESMTP id 992C82E0130 for ; Sun, 23 Dec 2007 19:02:58 -0400 (AST) Received: from vista (p54AD0811.dip0.t-ipconnect.de [84.173.8.17]) by 208091.vserver.de (8.12.8/8.12.8) with ESMTP id lBNN2uc6011827 for ; Mon, 24 Dec 2007 00:02:56 +0100 From: To: References: <20071223205557.GA14403@apartia.fr> <162867790712231327g774b8c5ld488113a3a8252e9@mail.gmail.com> <20071223213345.GA15623@apartia.fr> <162867790712231345w7c01493fv90517ba2dc9a90ff@mail.gmail.com> In-Reply-To: <162867790712231345w7c01493fv90517ba2dc9a90ff@mail.gmail.com> Subject: returning an array as a list of single-column rows... (different approach) Date: Mon, 24 Dec 2007 00:02:45 +0100 Message-ID: <001101c845b7$ee686590$cb3930b0$@de> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AchFrW7D02gOdyY7S2yskcHqgYb7pgABNGxQ Content-Language: de X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.225 tagged_above=0 required=5 tests=AWL=0.224, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200712/125 X-Sequence-Number: 29817 An: pgsql-sql@postgresql.org Betreff: Re: [SQL] returning an array as a list fo single-column rows? The following will return the elements of an array each in its Own row. Using both array_lower() and array_upper() the number of array Elements and their internal index may vary from record to record. Or may even be absent. Within the record the array nstat[],nwert[],nwho[] must correspond. Joining the table with generate_series(array_lower(nWert,1),array_upper(nWert,1)) as indx returns the contained array elements. Considering the following table with array..... Create table werte (id : integer, ...... ...... nstat : character(1)[], nwert : double precision[], nwho : character varying(9)[] ); select w.id,ii.indx, w.nStat[ii.indx],w.nWert[ii.indx],w.nWho[ii.indx] from werte w join ( select id, generate_series(array_lower(nWert,1),array_upper(nWert,1)) as indx from werte ) ii on ii.id=w.id ; Let me know what you think about this approach? My best regards, Stefan Becker