Обсуждение: Updating an array

Поиск
Список
Период
Сортировка

Updating an array

От
Renaud Tthonnart
Дата:
How can I append an element to an array, without read and rewrite the
full array.

CREATE TABLE xxx
(
 id int,
 nom varchar(10),
 nombres int[],

 PRIMARY KEY(id)

);

*** 1 ***
INSERT INTO xxx VALUES( 1,'aaa','{10,20,30,40}');
==> Here the row is well created.

*** 2 ***
UPDATE xxx
SET nombres[5]= 63
WHERE id = 1;
==> Here, I'd just append a new element to the array. That doesn't work

*** 3 ***
UPDATE xxx
SET nombres= '{10,20,30,40,63}'
WHERE id = 1;
==> That works, but needs to read out the array and to rewrite it. Is it
possible to avoid that?

Thanks,
Renaud THONNART



Re: Updating an array

От
Tom Lane
Дата:
Renaud Tthonnart <thonnart@amwdb.u-strasbg.fr> writes:
> *** 2 ***
> UPDATE xxx
> SET nombres[5]= 63
> WHERE id = 1;
> ==> Here, I'd just append a new element to the array. That doesn't work

This does work --- at least for one-dimensional arrays --- as of 7.1.

            regards, tom lane

Re: Updating an array

От
Renaud Tthonnart
Дата:
Tom Lane wrote:

> Renaud Tthonnart <thonnart@amwdb.u-strasbg.fr> writes:
> > *** 2 ***
> > UPDATE xxx
> > SET nombres[5]= 63
> > WHERE id = 1;
> > ==> Here, I'd just append a new element to the array. That doesn't work
>
> This does work --- at least for one-dimensional arrays --- as of 7.1.
>
>                         regards, tom lane

Ok, many thanks!
Renaud THONNART