From: | "Max Zorloff" <zorloff(at)gmail(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Declaring multidimensional arrays in pl/pgsql |
Date: | 2007-11-29 14:28:38 |
Message-ID: | op.t2j450qnll0p5y@1-rtt202dnf3uds.mshome.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 29 Nov 2007 18:11:22 +0400, Rodrigo De León <rdeleonp(at)gmail(dot)com>
wrote:
> On Nov 29, 2007 3:34 AM, Max Zorloff <zorloff(at)gmail(dot)com> wrote:
>> According to the docs it seems that only way would be to declare it as
>> something like :
>> myArray := ARRAY[[1,2], [3,4], [5,6]];
>
> You can declare arbitrary-sized, n-dimensional arrays:
> ...
> DECLARE
> myArray integer[][]; -- two-dimensional integer array
> BEGIN
> ...
> END;
> ...
>
> See:
> http://www.postgresql.org/docs/8.1/static/arrays.html
I can. But unfortunately :
create or replace function testfunc()
returns setof record as $$
DECLARE
myArray int[][];
BEGIN
FOR i IN 1..10 LOOP
FOR j IN 1..10 LOOP
RAISE NOTICE '% %', i, j;
myArray[i][j] := 1;
END LOOP;
END LOOP;
RETURN;
END
$$ language plpgsql;
ponline=# select testfunc();
NOTICE: 1 1
NOTICE: 1 2
ERROR: invalid array subscripts
КОНТЕКСТ: PL/pgSQL function "testfunc" line 7 at assignment
2-dimensional arrays do not grow like 1-dimensional do (it says so in the
docs).
The initial array is 1x1 size. I suppose I'm stuck with emulating 2-dim
arrays through
1-dim arrays because I also need them to grow later.
From | Date | Subject | |
---|---|---|---|
Next Message | Hiroshi Saito | 2007-11-29 14:47:39 | Re: Slony-I creation scripts not available |
Previous Message | Sim Zacks | 2007-11-29 14:25:13 | notify/listen disappearing data |