Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 006D44760AF for ; Sat, 28 Sep 2002 18:24:09 -0400 (EDT) Received: from post.webmailer.de (natpost.webmailer.de [192.67.198.65]) by postgresql.org (Postfix) with ESMTP id E2CC6475EC9 for ; Sat, 28 Sep 2002 18:24:07 -0400 (EDT) Received: from ianb.local (pD9517581.dip.t-dialin.net [217.81.117.129]) by post.webmailer.de (8.9.3/8.8.7) with ESMTP id AAA02858; Sun, 29 Sep 2002 00:23:48 +0200 (MET DST) Content-Type: text/plain; charset="iso-8859-1" From: Ian Barwick To: "Josh Berkus" , Greg Johnson , pgsql-sql@postgresql.org Subject: Re: Passing array to PL/SQL and looping Date: Sun, 29 Sep 2002 00:25:06 +0200 X-Mailer: KMail [version 1.4] References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200209290025.06378.barwick@gmx.net> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/396 X-Sequence-Number: 9673 On Friday 27 September 2002 18:04, Josh Berkus wrote: > Greg, > > > CREATE FUNCTION test_array( ) RETURNS VARCHAR[] AS ' > > DECLARE > > return_array VARCHAR[]; > > BEGIN > > return_array[0] :=3D ''test''; > > return_array[1] :=3D ''test 1''; > > return_array[2] :=3D ''test 2''; > > RETURN (return_array); > > END;' > > LANGUAGE 'plpgsql'; > > No, it's not possible to do the above. This is a flaw in the current > implementation of PL/pgSQL that will not be resolved until we attract > some new Postgres hackers who really care about upgrading PL/pgSQL. > > Currently, if you want to use an array, it has to be passed as a > parameter, or come from an external table. You cannot declare an > Array data type. Annoying, really. If I replace the return_array allocations in the above example with this=20 line: return_array :=3D ''{ ''''test'''', ''''test 1'''', ''''test 2''''}''; it _seems_ to work as expected, at least in 7.3b1., e.g.=20 test=3D> select array_dims(test_array) from test_array(); array_dims=20 ------------ [1:3] (1 row) Ian Barwick barwick@gmx.net