Atomic/locked "allocation" of table row?

Поиск
Список
Период
Сортировка
От Sten Daniel Soersdal
Тема Atomic/locked "allocation" of table row?
Дата
Msg-id 46B68136.1090206@gmail.com
обсуждение исходный текст
Ответы Re: Atomic/locked "allocation" of table row?  (Richard Broersma Jr <rabroersma@yahoo.com>)
Re: Atomic/locked "allocation" of table row?  (Rodrigo De León <rdeleonp@gmail.com>)
Список pgsql-novice
CREATE TABLE tunnel (
    username    integer UNIQUE, -- ranges from 1 to ~250.000
    password    varchar
);

I need to write a function to "allocate" an empty "tunnel" on a
prepopulated table where all fields, except username, IS NULL by default.

In essence this function would do;

UPDATE SET password = 'mysecret' WHERE username = ( SELECT username FROM
tunnel WHERE password IS NULL LIMIT 1 );

But i need to know that no other concurrently running session would
allocate that specific row in between the SELECT ... and the UPDATE.

Could this be done atomically somehow? Is it necessary to add some kind
of locking? Help?

--
Sten Daniel Soersdal

В списке pgsql-novice по дате отправления:

Предыдущее
От: Oliver Elphick
Дата:
Сообщение: Re: Postgresql on 64bit Debian 4.0: libz.so.1 => not found
Следующее
От: Richard Broersma Jr
Дата:
Сообщение: Re: Atomic/locked "allocation" of table row?