Re: Row Locking - Mailing list pgsql-general

From Patrick Welche
Subject Re: Row Locking
Date
Msg-id 20020520173630.J11643@quartz.newn.cam.ac.uk
Whole thread Raw
In response to Re: Row Locking  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-general by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: On using "date 'XXX' + interval 'XXX'" vs "date 'XXX'"
Next
From: Cindy
Date:
Subject: Re: sun solaris & postgres