Skip site navigation (1) Skip section navigation (2)

Re: Question Regarding Locks

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Question Regarding Locks
Date: 2004-10-28 17:07:21
Message-ID: 3126.1098983241@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novice
Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net> writes:
> Just so that I am not getting this wrong:
>> BTW, a handy proxy for "row has not changed" is to see if its XMIN
>> system column is still the same as before.
> Considering that my business objects remember XMIN from when
> they first got the row would the following sequence make sure
> I am in good shape ?

> begin;
>     select ... for update;
>     update ... set ... where
> 	my_pk=<my_pk_value>
> 	    AND
> 	xmin=<the_old_xmin>

> This should either update 1 row in which case I can commit or
> zero rows in which case I need to rollback and handle the merge
> conflict. The reasoning would be that the condition
> my_pk=my_pk_value would select the row I am interested in
> while xmin=the_old_xmin would ensure that row hasn't been
> modified.

> Am I right or is there a flaw in my thinking ?

I think you can skip the SELECT FOR UPDATE altogether if you do it that
way.  Otherwise it looks fine.

			regards, tom lane

In response to

Responses

pgsql-novice by date

Next:From: Michael FuhrDate: 2004-10-28 17:33:20
Subject: Re: Retrieve columntypes and checks?
Previous:From: Jesper KroghDate: 2004-10-28 17:03:27
Subject: Re: Retrieve columntypes and checks?

pgsql-general by date

Next:From: Tom LaneDate: 2004-10-28 17:18:16
Subject: Re: field incrementing in a PL/pgSQL trigger
Previous:From: Marco ColomboDate: 2004-10-28 16:23:14
Subject: Re: Reasoning behind process instead of thread based

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group