Re: Populating a sparse array piecemeal in plpgsql

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Eliot, Christopher" <christopher(dot)eliot(at)nagrastar(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Populating a sparse array piecemeal in plpgsql
Date: 2008-05-15 15:40:22
Message-ID: 5562.1210866022@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Eliot, Christopher" <christopher(dot)eliot(at)nagrastar(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Manes 2008-05-15 15:40:49 Re: Password safe web application with postgre
Previous Message Steve Crawford 2008-05-15 14:48:36 Re: Password safe web application with postgre*s*