Re: Processing a work queue

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Steve Crawford" <scrawford(at)pinpointresearch(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Processing a work queue
Date: 2007-04-27 00:43:22
Message-ID: b42b73150704261743x4f193408o15399f1864d25d02@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 4/27/07, Merlin Moncure <mmoncure(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kenneth Downs 2007-04-27 00:47:46 Re: plperl functions not re-entrant?
Previous Message Bruce Momjian 2007-04-27 00:39:46 Re: dropping role w/dependent objects