Re: Row Locking

From: Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Row Locking
Date: 2002-05-20 16:36:30
Message-ID: 20020520173630.J11643@quartz.newn.cam.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, May 20, 2002 at 10:24:06AM -0400, Tom Lane wrote:
...
> The only sorts of row-level locks we use are those acquired by
> updating/deleting an existing row, or equivalently by SELECT FOR UPDATE
> (which doesn't change the row, but marks it as if it did). These
> locks do not prevent another transaction from reading the row with
> SELECT --- only from updating, deleting, or selecting it FOR UPDATE.
>
> All locks are held till transaction commit.

I'm trying to use select for update with libpq++. Is this possible as each
Exec seems to have its own transaction. I would like to

begin;
select 1
from locktable, other, tables
where locktable.id="<<lock<<"
and the_rest

db.ExecTuplesOk <===== I think this terminates the "begin" => no more lock..

if db.Tuples != 1 throw exeception("someone else edited your row")

update tables set x=1,y=2
where tables.id=locktable.tables
and locktable.id="<<lock<<"
delete from locktable where id="<<lock<<"
end; <===== I would like the transaction to end here!
db.ExecCommandOk

I think each Exec has its own transaction because

DEBUG: StartTransactionCommand
DEBUG: query: begin;select 1...
DEBUG: ProcessUtility: begin;select 1...
DEBUG: CommitTransactionCommand
DEBUG: StartTransactionCommand
DEBUG: ProcessQuery
DEBUG: CommitTransactionCommand
DEBUG: StartTransactionCommand
DEBUG: query: update...;end;
DEBUG: ProcessQuery
DEBUG: ProcessQuery
DEBUG: ProcessQuery
DEBUG: ProcessUtility: update...;end;
... refint select 1 for updates...
DEBUG: CommitTransactionCommand

or does "CommitTransactionCommand" not imply an "end;"?

Cheers,

Patrick

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gareth Kirwan 2002-05-20 16:40:46 Re: Interval to number
Previous Message Brian McCane 2002-05-20 16:35:07 Re: Interval to number