select for update question

Поиск
Список
Период
Сортировка
От A B
Тема select for update question
Дата
Msg-id dbbf25901001121534m33d21c26s9062c56296774fe7@mail.gmail.com
обсуждение исходный текст
Ответы Re: select for update question
Список pgsql-novice
Hello there.
I'm looking into how to update a row in a table while protecting it
from access by others.

so far I've come up with this solution:

create function dostuff() returns void as $$
declare
  tmp integer;
begin
  select id into tmp from tableX where id>305 limit 1 for update;
  update tableX set some_field = some_value where id=tmp;
end; $$ language plpgsql;

will that guarantee that  the row I selected wil be updated within
this function and no one else can sneak in between and update or
delete the row?


What would I use if I would write

lock table   tableX  IN .... MODE  at the start of my function?

Any particular benefit with either method?

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

Предыдущее
От: e-letter
Дата:
Сообщение: connection to database via xforms
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: select for update question