Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DA9F72E1D81 for ; Sun, 23 Dec 2007 17:33:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 09534-06 for ; Sun, 23 Dec 2007 17:33:49 -0400 (AST) Received: from sargon.lncsa.com (sargon.lncsa.com [212.99.8.251]) by postgresql.org (Postfix) with ESMTP id 7D12E2E037C for ; Sun, 23 Dec 2007 17:33:48 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id 577B33027926 for ; Sun, 23 Dec 2007 22:33:47 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lncsa.com Received: from sargon.lncsa.com ([127.0.0.1]) by localhost (sargon.lncsa.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3oFvITvwvhoo for ; Sun, 23 Dec 2007 22:33:47 +0100 (CET) Received: from zenon.apartia.fr (zenon.apartia.fr [10.0.3.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "zenon.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by sargon.lncsa.com (Postfix) with ESMTP id E2A68302790F for ; Sun, 23 Dec 2007 22:33:46 +0100 (CET) Received: from timgad.apartia.fr (AToulouse-256-1-15-214.w90-38.abo.wanadoo.fr [90.38.98.214]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "timgad.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by zenon.apartia.fr (Postfix) with ESMTP id 0AC6159C5B428 for ; Sun, 23 Dec 2007 22:33:45 +0100 (CET) Received: by timgad.apartia.fr (Postfix, from userid 1000) id C59FE2C0692BB; Sun, 23 Dec 2007 22:33:45 +0100 (CET) Date: Sun, 23 Dec 2007 22:33:45 +0100 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: Re: returning an array as a list fo single-column rows? Message-ID: <20071223213345.GA15623@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org References: <20071223205557.GA14403@apartia.fr> <162867790712231327g774b8c5ld488113a3a8252e9@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <162867790712231327g774b8c5ld488113a3a8252e9@mail.gmail.com> User-Agent: Mutt/1.5.17 (2007-11-01) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/123 X-Sequence-Number: 29815 On Sun, Dec 23, 2007 at 10:27:09PM +0100, Pavel Stehule wrote: > On 23/12/2007, Louis-David Mitterrand > wrote: > > Hi, > > > > is there a way to return a Pg array as a list of single-column row > > values? > > > > I am trying to circumvent DBI's lack of support for native database > > arrays and return the list of values from an ENUM as a perl array. > > > > Thanks, > > > > you can solve this problem with conversion to string with const separator > > Like: > > postgres=# select array_to_string(array[1,2,3,4],'|'); > array_to_string > ----------------- > 1|2|3|4 > (1 row) > > [pavel@localhost ~]$ perl > @a = split(/\|/, "1|2|3"); > print $a[1]; Yes I thought about it, but would rather have Pg do the array splitting. For instance if the separator occurs in an array element there is no built-in escaping: % select array_to_string(array['ee','dd','rr','f|f'],'|'); array_to_string ----------------- ee|dd|rr|f|f ... and then perl would have it all wrong.