Re: Passing array to PL/SQL and looping

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ian Barwick <barwick(at)gmx(dot)net>
Cc: "Josh Berkus" <josh(at)agliodbs(dot)com>, Greg Johnson <gregj(at)interprose(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Passing array to PL/SQL and looping
Date: 2002-09-29 02:14:46
Message-ID: 6945.1033265686@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Ian Barwick <barwick(at)gmx(dot)net> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-09-29 02:18:18 Re: Passing array to PL/SQL and looping
Previous Message Roland Roberts 2002-09-29 00:27:37 Re: Passing array to PL/SQL and looping