| From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
|---|---|
| To: | Hannu Krosing <hannu(at)skype(dot)net> |
| Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Jonathan Scher <js(at)oxado(dot)com>, pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: UPSERT |
| Date: | 2007-03-04 15:49:49 |
| Message-ID: | 20070304154949.GB11685@svana.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sun, Mar 04, 2007 at 02:55:47PM +0200, Hannu Krosing wrote:
> Is'nt the standard way of doing it thus:
>
> UPDATE
> IF NOT FOUND THEN
> INSERT
> IF DUPLICATE KEY THEN
> UPDATE
> END IF
> END IF
>
> At least this is how UPSERT is usually done in plpgsql
Well, you need to loop, because that last UPDATE can get a not-found
again, so you have to keep trying both until they work.
I think MERGE would still be cool, because then it's only one command
that has to be repeated, rather than two.
Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Shane Ambler | 2007-03-04 15:56:38 | Re: ERROR: operator does not exist: integer !=- integer |
| Previous Message | Petr Jelinek | 2007-03-04 15:06:05 | Re: UPSERT |