From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Blake Starkenburg <blake(at)oldride(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Possible to UPDATE array[] columns? |
Date: | 2009-10-30 18:21:39 |
Message-ID: | 162867790910301121q387e5795t97ccb9aaf36fe424@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2009/10/30 Blake Starkenburg <blake(at)oldride(dot)com>:
> Using SQL is it possible to UPDATE (append) onto an array[] column. For
> example say I have a column named "scores int[]".
>
> ID | scores
> 2 | {54,14,21,8}
> 3 | {12,0,7}
>
> Now I want to append the score of 12 on row:ID 2 so the new scores would
> read {54,14,21,8,12}. I thought maybe simply leaving the array key empty
> would auto-append "UPDATE table set scores[] = 12 WHERE id = 2", not so....
>
> Thanks!
>
postgres=# create table foo(a int[]);
CREATE TABLE
postgres=# insert into foo values('{}');
INSERT 0 1
postgres=# update foo set a = a || 10;
UPDATE 1
postgres=# update foo set a = a || 20;
UPDATE 1
postgres=# update foo set a = a || 30;
UPDATE 1
postgres=# select * from foo;
a
------------
{10,20,30}
(1 row)
regards
Pavel Stehule
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
From | Date | Subject | |
---|---|---|---|
Next Message | Sam Mason | 2009-10-30 18:23:28 | Re: Possible to UPDATE array[] columns? |
Previous Message | Mark Morgan Lloyd | 2009-10-30 18:21:30 | Re: CREATE TABLE LIKE and SERIAL |