Table locking. - Mailing list pgsql-sql

From Michael Richards
Subject Table locking.
Date
Msg-id 3A5D2611.00001D.86746@frodo.searchcanada.ca
Whole thread Raw
List pgsql-sql
Hi.

I've always had trouble understanding how to properly deal with the 
following case.

I need to run an insert on a table but I don't want any other 
transactions to commit the insert before me. Within the logic of the 
program, I run a select to see if there is a value there, then the 
insert. Between these 2 statements someone could commit one that 
causes the insert to fail.

Is there a better way to do this than locking the table in SHARE ROW 
EXCLUSIVE MODE and trying to be certain that anything else that may 
call an insert there asks for the same type of lock?

-Michael
_________________________________________________________________    http://fastmail.ca/ - Fast Free Web Email for
Canadians

pgsql-sql by date:

Previous
From: Joel Burton
Date:
Subject: Re: connecting to postgres server from Access
Next
From: Vince Vielhaber
Date:
Subject: Re: [HACKERS] Re: PostgreSQL web page