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

From: Edson Richter <edsonrichter(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: is there a select for update insert if not exist type command?
Date: 2012-06-09 23:57:50
Message-ID: BLU0-SMTP3246D2E75F7F7E8F7A60C6ACFF10@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

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.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message David Johnston 2012-06-10 00:10:38 Re: is there a select for update insert if not exist type command?
Previous Message Bill Moran 2012-06-09 23:35:22 Re: is there a select for update insert if not exist type command?

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2012-06-10 00:10:38 Re: is there a select for update insert if not exist type command?
Previous Message Bill Moran 2012-06-09 23:35:22 Re: is there a select for update insert if not exist type command?