Updating an array - Mailing list pgsql-general

From Renaud Tthonnart
Subject Updating an array
Date
Msg-id 3A9697A6.578FB837@amwdb.u-strasbg.fr
Whole thread Raw
Responses Re: Updating an array  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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



pgsql-general by date:

Previous
From: ochapiteau
Date:
Subject: drop a constraint
Next
From: Alex Pilosov
Date:
Subject: Re: drop a constraint