pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Edson Richter <edsonrichter@hotmail.com>
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:57:50 -0300
Message-ID: <BLU0-SMTP3246D2E75F7F7E8F7A60C6ACFF10@phx.gbl> (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>

You will find this reading a good start point: 
http://www.cs.uiuc.edu/class/fa07/cs411/lectures/cs411-f07-tranmgr-3.pdf

There are no "fit all needs" cookbook about this, you will have to learn 
the theory about transactional database transaction management and 
locking mechanism and work on your solution.

Wish you the best,


Edson.

Em 09/06/2012 19:41, Evan Rempel escreveu:
> I have a project where I will have two clients essentially doing the
> same things at the same time. The idea is that if one has already done the
> work, then the second one does not need to do it.
>
> I was hoping that adding a task related unique identifier to a table
> could be used to coordinate these client, something like a primary key and using
> select for update.
>
> The challenge I have is during the initial insert. One of the two clients will cause postgresql
> to log an error, which I would rather avoid (just seems dirty).
>
> Here is the time line;
>
> Both clients A and B becomes aware to do a task
>
> Client A or client B issues the "select for update ... if not exist do insert" type command
> The other client gets blocked on the "select for update.
>
> First client finishes insert/updates to record that it has delt with the task
>
> second client gets unblocked and reads the record realizing that the first client delt with the task already.
>
>
> It is the "select for update ... if not exist do insert" type command that I am ignorant of how to code.
>
> Anyone care to school me?
>
> Evan.




view thread (7+ messages)  latest in thread

Message-ID: <BLU0-SMTP3246D2E75F7F7E8F7A60C6ACFF10@phx.gbl>
Permalink:  ../BLU0-SMTP3246D2E75F7F7E8F7A60C6ACFF10@phx.gbl/
Also on:    postgresql.org/message-id/BLU0-SMTP3246D2E75F7F7E8F7A60C6ACFF10@phx.gbl

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: edsonrichter@hotmail.com, pgsql-general@postgresql.org
  Subject: Re: is there a select for update insert if not exist type command?
  In-Reply-To: <BLU0-SMTP3246D2E75F7F7E8F7A60C6ACFF10@phx.gbl>
  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> <BLU0-SMTP3246D2E75F7F7E8F7A60C6ACFF10@phx.gbl>

* 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