Re: UPSERT

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: UPSERT
Дата
Msg-id 20070304154949.GB11685@svana.org
обсуждение исходный текст
Ответ на Re: UPSERT  (Hannu Krosing <hannu@skype.net>)
Список 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 по дате отправления:

Предыдущее
От: Petr Jelinek
Дата:
Сообщение: Re: UPSERT
Следующее
От: Shane Ambler
Дата:
Сообщение: Re: ERROR: operator does not exist: integer !=- integer