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

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'Evan Rempel'" <erempel(at)uvic(dot)ca>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: is there a select for update insert if not exist type command?
Date: 2012-06-10 00:10:38
Message-ID: 001a01cd469d$791b6260$6b522720$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin 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.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Evan Rempel 2012-06-10 02:40:12 Re: is there a select for update insert if not exist type command?
Previous Message Edson Richter 2012-06-09 23:57:50 Re: is there a select for update insert if not exist type command?

Browse pgsql-general by date

  From Date Subject
Next Message Evan Rempel 2012-06-10 02:40:12 Re: is there a select for update insert if not exist type command?
Previous Message Edson Richter 2012-06-09 23:57:50 Re: is there a select for update insert if not exist type command?