Row Locking - Mailing list pgsql-general

From Alexander Klayman
Subject Row Locking
Date
Msg-id 200205192353.23312.aklayman@mindspring.com
Whole thread Raw
Responses Re: Row Locking
List pgsql-general
I have a few basic question and either need an affirmation or correction.
Thank you very much for help in advance.

When using Row locks, when does the lock start, which rows does it lock and
when does it end?  I was unable to find this info in documentation (maybe
because it is supposed to be implicit).  I have the following idea:

BEGIN;
LOCK TABLE A IN ROW EXCLUSIVE MODE;
SELECT c FROM A WHERE id=1;   # The row with d=1 is locked
if c then
  DELETE FROM A WHEE id=1;
COMMIT;                            # The row (if remaining) is unlocked


Also, could I do something like this:

BEGIN;
LOCK TABLE A IN ROW EXCLUSIVE MODE;
cursor = SELECT c, id FROM A WHERE d=1;
while cursor.fetchone() # Next row is locked, previous row
  if c then                    #  (if remaining) is unlocked
    DELETE FROM A WHERE id=id;

COMMIT;

Thanks.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: DBD::Pg: Placeholders not working
Next
From: Jean-Michel POURE
Date:
Subject: Re: [HACKERS] UTF-8 safe ascii() function