Do I have to lock table in this case?

From: Ondrej Palkovsky <xpalo03(at)vse(dot)cz>
To: pgsql-sql(at)postgresql(dot)org
Subject: Do I have to lock table in this case?
Date: 2001-06-09 15:50:11
Message-ID: Pine.LNX.4.20.0106091746160.2590-100000@ondra.debian.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a table like this:
id primary key
unique

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.

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2001-06-09 16:17:05 Re: Inconsistent usage of Index
Previous Message Subra Radhakrishnan 2001-06-09 15:18:02 Inconsistent usage of Index