Re: is there a select for update insert if not exist type command?

Поиск
Список
Период
Сортировка
От Chris Travers
Тема Re: is there a select for update insert if not exist type command?
Дата
Msg-id CAKt_ZfuoUW1mrFv74Ye3jH9UFOqCx-QJ2GdJEfcMjyiZf0uC+w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: is there a select for update insert if not exist type command?  ("David Johnston" <polobo@yahoo.com>)
Список pgsql-general
Depending on the version of Pg there are two possible solutions to
this problem.  The first (old solution) that really only works well
one row at a time is to do a stored procedure that does something
like:

update foo set bar = baz where id = in_id

if not found
   insert into foo (bar) values (baz)
end if;

The newer way, which can be done in SQL with Pg 9.1 is to use writable
common table expressions.  See
http://vibhorkumar.wordpress.com/2011/10/26/upsertmerge-using-writable-cte-in-postgresql-9-1/
for an example by Vibhor Kumar.

Best Wishes,
Chris Travers

В списке pgsql-general по дате отправления:

Предыдущее
От: Evan Rempel
Дата:
Сообщение: Re: is there a select for update insert if not exist type command?
Следующее
От: Edson Richter
Дата:
Сообщение: Re: is there a select for update insert if not exist type command?