Re: INSERT OR UPDATE

Поиск
Список
Период
Сортировка
От Guy Rouillier
Тема Re: INSERT OR UPDATE
Дата
Msg-id CC1CF380F4D70844B01D45982E671B239E8DD9@mtxexch01.add0.masergy.com
обсуждение исходный текст
Ответ на INSERT OR UPDATE  ("Julian Scarfe" <julian@avbrief.com>)
Список pgsql-general
Julian Scarfe wrote:
> I'm keeping config information for an application in a series of
> related tables.  I'd like a command that INSERTs data if it's new,
< or UPDATEs it if the key is duplicated.

Write a stored procedure called something like InsertUpdateConfigData.
Pick the operation that you think is most likely to occur more often
(the insert or update).  Code that as the initial statement.  Then
create an exception block, and in that exception block catch the error
that would result from the initial statement being executed in the case
where the other one should have been; then execute that other statement.

There is no magic database-provided SQL statement that says "try an
insert and if that fails then try an update."  You have to do that
yourself.

--
Guy Rouillier


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

Предыдущее
От: Tyler MacDonald
Дата:
Сообщение: Re: inserting many rows
Следующее
От: Lucky Leavell
Дата:
Сообщение: Ident authentication failed