Do I have to lock table in this case? - Mailing list pgsql-sql

From Ondrej Palkovsky
Subject Do I have to lock table in this case?
Date
Msg-id Pine.LNX.4.20.0106091746160.2590-100000@ondra.debian.cz
Whole thread Raw
List pgsql-sql
I have a table like this:id primary keyunique

I need to do:- if 'unique' exists in table, return appropriate id
else insert into table new id.
Now doing:
select id where unique=%s 
insert/update 
creates a race condition. The application can theoretically rollback &
redo the whole transaction (not simple in some cases). What is the
preferred solution to this problem (I got about 3 such cases in one simple
application).

Ondrej

--
It is better to remain childless than to father an orphan.



pgsql-sql by date:

Previous
From: david.brown@mviva.net (David Brown)
Date:
Subject: listing foreign keys
Next
From: Alex Pilosov
Date:
Subject: Re: PL/PGSQL