pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Johnston <polobo@yahoo.com>
To: 'Evan Rempel' <erempel@uvic.ca>
To: pgsql-general@postgresql.org
Subject: Re: is there a select for update insert if not exist type command?
Date: Sat, 9 Jun 2012 20:10:38 -0400
Message-ID: <001a01cd469d$791b6260$6b522720$@yahoo.com> (raw)
In-Reply-To: <F1226B1821911E4BB69462DAF68098536E3233376B@EMC6.uvic.ca>
References: <4F8B6AA1.1040709@zvelo.com>
	<20120416065717.70a31a6361ac5d7bdad416e8@frank.uvena.de>
	<4F8BD91C.6070405@zvelo.com>
	<4F8BDAB2.7010209@frank.uvena.de>
	<4F8C248E.7070307@zvelo.com>
	<4F8CC11A.5020003@d2.com>
	<4F8CDB95.3040407@zvelo.com>
	<A76B25F2823E954C9E45E32FA49D70EC03DACFB6@mail.corp.perceptron.com>
	<4F8E04D9.6010402@zvelo.com>
	<F1226B1821911E4BB69462DAF68098536E32333755@EMC6.uvic.ca>
	<20120531093728.GA25109@depesz.com>
	<F1226B1821911E4BB69462DAF68098536E3233376B@EMC6.uvic.ca>

> -----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.







view thread (7+ messages)  latest in thread

Message-ID: <001a01cd469d$791b6260$6b522720$@yahoo.com>
Permalink:  ../001a01cd469d$791b6260$6b522720$@yahoo.com/
Also on:    postgresql.org/message-id/001a01cd469d$791b6260$6b522720$@yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: polobo@yahoo.com, erempel@uvic.ca, pgsql-general@postgresql.org
  Subject: Re: is there a select for update insert if not exist type command?
  In-Reply-To: <001a01cd469d$791b6260$6b522720$@yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox