Re: Populating a sparse array piecemeal in plpgsql - Mailing list pgsql-general

From Tom Lane
Subject Re: Populating a sparse array piecemeal in plpgsql
Date
Msg-id 5562.1210866022@sss.pgh.pa.us
Whole thread Raw
In response to Re: Populating a sparse array piecemeal in plpgsql  ("Eliot, Christopher" <christopher.eliot@nagrastar.com>)
Responses Re: Populating a sparse array piecemeal in plpgsql  ("Eliot, Christopher" <christopher.eliot@nagrastar.com>)
List pgsql-general
"Eliot, Christopher" <christopher.eliot@nagrastar.com> writes:
> Thank you for your reply, but I don't really understand how to use this
> information.
> My problem is that I can put one value into this array, and that's it.
> Any subsequent attempts to put another value elsewhere in the array are
> rebuffed, saying that the subscripts are out of range.  I don't
> understand what I would do "by hand" that would help this.

Well, the point is that you need to initialize the array as a whole to
have the dimensions you want; PG won't guess about this.  For instance
you could do something like

    declare a integer[];
    begin
      a := '{{null,null,null},{null,null,null},{null,null,null}}';

which sets up a null-filled 3x3 array that you can then manipulate
individual elements of.  For the sorts of dimensions you were showing,
writing out the initial value as a constant would be pretty dang
tedious, but you could build up the textual value in a loop and then
assign it.

To be honest, I wonder whether you are working in the wrong language.
PG (and therefore plpgsql) isn't very good with multidimensional arrays,
and especially not large ones.  Perhaps you ought to be pushing your
data around in pl/R or some such.

            regards, tom lane

pgsql-general by date:

Previous
From: Steve Crawford
Date:
Subject: Re: Password safe web application with postgre*s*
Next
From: Steve Manes
Date:
Subject: Re: Password safe web application with postgre