Search Postgresql Archives

Re: Declaring multidimensional arrays in pl/pgsql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 29 Nov 2007 18:11:22 +0400, Rodrigo De León <rdeleonp@xxxxxxxxx> wrote:

On Nov 29, 2007 3:34 AM, Max Zorloff <zorloff@xxxxxxxxx> 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.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux