| From: | Thom Brown <thombrown(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:18:53 |
| Message-ID: | bddc86150910301118m3a029dddq77eda1a465b6e5ef@mail.gmail.com |
| Views: | Whole Thread | Raw Message | 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....
>
You could use the concatenation operator
so it would be:
UPDATE TABLE set scores[] = scores[] || 12
WHERE id = 2;
Thom
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Mark Morgan Lloyd | 2009-10-30 18:21:30 | Re: CREATE TABLE LIKE and SERIAL |
| Previous Message | Blake Starkenburg | 2009-10-30 17:47:26 | Possible to UPDATE array[] columns? |