Re: is there a select for update insert if not exist type command? - Mailing list pgsql-general

From David Johnston
Subject Re: is there a select for update insert if not exist type command?
Date
Msg-id 001a01cd469d$791b6260$6b522720$@yahoo.com
Whole thread Raw
In response to is there a select for update insert if not exist type command?  (Evan Rempel <erempel@uvic.ca>)
Responses Re: is there a select for update insert if not exist type command?  (Chris Travers <chris.travers@gmail.com>)
List 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 by date:

Previous
From: Edson Richter
Date:
Subject: Re: is there a select for update insert if not exist type command?
Next
From: Evan Rempel
Date:
Subject: Re: is there a select for update insert if not exist type command?