Re: Processing a work queue

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: Processing a work queue
Дата
Msg-id b42b73150704261743x4f193408o15399f1864d25d02@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Processing a work queue  ("Merlin Moncure" <mmoncure@gmail.com>)
Список pgsql-general
On 4/27/07, Merlin Moncure <mmoncure@gmail.com> wrote:
> how about this:
> create table job(job_id int, [...])
> create sequence worker;
>

couple typos: here is an example that works:
create table job(job_id serial);
create sequence worker;

-- get next available job
create function next_job() returns job as
$$
select job from job join
(
 select nextval('worker') as requested_job
) q on job_id = requested_job
and
(
 (select (w.last_value, w.is_called) < (j.last_value, j.is_called)
from worker w, job_job_id_seq j)
);
$$ language sql;

select next_job();

again, remembering that sequences are not rolled back on transaction
failure, you have to think really carefully about failure conditions
before going with something like this.

merlin

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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: dropping role w/dependent objects
Следующее
От: Kenneth Downs
Дата:
Сообщение: Re: plperl functions not re-entrant?