Re: Populating a sparse array piecemeal in plpgsql

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Populating a sparse array piecemeal in plpgsql
Дата
Msg-id 5562.1210866022@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Populating a sparse array piecemeal in plpgsql  ("Eliot, Christopher" <christopher.eliot@nagrastar.com>)
Ответы Re: Populating a sparse array piecemeal in plpgsql  ("Eliot, Christopher" <christopher.eliot@nagrastar.com>)
Список 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 по дате отправления:

Предыдущее
От: Steve Crawford
Дата:
Сообщение: Re: Password safe web application with postgre*s*
Следующее
От: Steve Manes
Дата:
Сообщение: Re: Password safe web application with postgre