Re: UPSERT - Mailing list pgsql-hackers

From Martijn van Oosterhout
Subject Re: UPSERT
Date
Msg-id 20070304154949.GB11685@svana.org
Whole thread Raw
In response to Re: UPSERT  (Hannu Krosing <hannu@skype.net>)
List 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@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

pgsql-hackers by date:

Previous
From: Petr Jelinek
Date:
Subject: Re: UPSERT
Next
From: Shane Ambler
Date:
Subject: Re: ERROR: operator does not exist: integer !=- integer