Re: easy task: concurrent select-updates

Поиск
Список
Период
Сортировка
От Kevin McConnell
Тема Re: easy task: concurrent select-updates
Дата
Msg-id 372194e70909031205i7ca1074o46f3fdc67cf613c6@mail.gmail.com
обсуждение исходный текст
Ответ на Re: easy task: concurrent select-updates  (Andy Colson <andy@squeakycode.net>)
Ответы Re: easy task: concurrent select-updates  (Andy Colson <andy@squeakycode.net>)
Re: easy task: concurrent select-updates  (Nickolay <nitro@zhukcity.ru>)
Список pgsql-general
> CREATE OR REPLACE FUNCTION public.getmsg() RETURNS integer LANGUAGE plpgsql
> AS $function$
> declare
>       rec record;
> begin
>       for rec in select id from msg where busy = false order by id loop
>               update msg set busy = true where id = rec.id and busy = false;
>               if found then
>                       return rec.id;
>               end if;
>       end loop;
>       return -1;
> end;
> $function$

I think you could also do something roughly similar in a statement by
using a RETURNING clause on the update, such as:

  update msg set busy = true where id = (select min(id) from msg where
busy = false) returning *;

Cheers,
Kevin

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

Предыдущее
От: "Shakil Shaikh"
Дата:
Сообщение: Re: Create language PLPERL error
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: Create language PLPERL error