Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id C1BC7476069 for ; Sat, 28 Sep 2002 22:15:18 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 2F45B475F09 for ; Sat, 28 Sep 2002 22:15:18 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g8T2EkhR006946; Sat, 28 Sep 2002 22:14:46 -0400 (EDT) To: Ian Barwick Cc: "Josh Berkus" , Greg Johnson , pgsql-sql@postgresql.org Subject: Re: Passing array to PL/SQL and looping In-reply-to: <200209290025.06378.barwick@gmx.net> References: <200209290025.06378.barwick@gmx.net> Comments: In-reply-to Ian Barwick message dated "Sun, 29 Sep 2002 00:25:06 +0200" Date: Sat, 28 Sep 2002 22:14:46 -0400 Message-ID: <6945.1033265686@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/398 X-Sequence-Number: 9675 Ian Barwick writes: > On Friday 27 September 2002 18:04, Josh Berkus wrote: >> 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 > line: > return_array := ''{ ''''test'''', ''''test 1'''', ''''test 2''''}''; > it _seems_ to work as expected, at least in 7.3b1. Yes, operations that work on whole-array values work fine in plpgsql. It's accesses to array elements that aren't supported well. The main case that seems to be missing in current sources is exactly assignment to an array element, ie foo[n] := something. More generally --- and this is really a shortcoming in our SQL language, not specifically in plpgsql --- there isn't any way to construct an array value as an expression result. I can imagine writing something like SELECT CAST(1,2,3 AS int[3]); but we've got nothing like that at the moment. (If you don't see the point of this as compared to SELECT CAST('{1,2,3}' AS int[3]); then think about replacing the 1, 2, and 3 by arbitrary integer expressions.) regards, tom lane