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

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: is there a select for update insert if not exist type command?
Дата
Msg-id 001a01cd469d$791b6260$6b522720$@yahoo.com
обсуждение исходный текст
Ответ на is there a select for update insert if not exist type command?  (Evan Rempel <erempel@uvic.ca>)
Ответы Re: is there a select for update insert if not exist type command?  (Chris Travers <chris.travers@gmail.com>)
Список pgsql-general
> -----Original Message-----
>
> Both clients A and B becomes aware to do a task
>

Ideally you would have this aware-ness manifested as an INSERT into some
kind of job table.  The clients can issue the "SELECT FOR UPDATE" + "UPDATE"
commands to indicate that they are going to be responsible for said task.
You seem to combining "something needs to be done" with "I am able to do
that something".  You may not have a choice depending on your situation but
it is something to think about - how can I just focus on implementing the
"something needs to be done" part.

If you want to avoid the errors appearing in the logs or client you could
just wrap the INSERT command into a function and trap the duplicate key
exception.

It is hard to give suggestions when you are as vague as "becomes aware to do
a task".  Ideally even if you have multiple clients monitoring for "aware
state" only one client should ever actually realize said awareness for a
given task.  In effect you want to serialize the monitoring routine at this
level, insert the "something needs to be done" record, then serialize (for
update) the "I am able to do that something" action.

David J.





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

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