Re: Declaring multidimensional arrays in pl/pgsql
От | Max Zorloff |
---|---|
Тема | Re: Declaring multidimensional arrays in pl/pgsql |
Дата | |
Msg-id | op.t2j450qnll0p5y@1-rtt202dnf3uds.mshome.net обсуждение исходный текст |
Ответ на | Re: Declaring multidimensional arrays in pl/pgsql ("Rodrigo De León" <rdeleonp@gmail.com>) |
Список | pgsql-general |
On Thu, 29 Nov 2007 18:11:22 +0400, Rodrigo De León <rdeleonp@gmail.com> wrote: > On Nov 29, 2007 3:34 AM, Max Zorloff <zorloff@gmail.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.
В списке pgsql-general по дате отправления: