Re: Processing a work queue

From: Lexington Luthor <lexington(dot)luthor(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Processing a work queue
Date: 2007-04-28 08:19:54
Message-ID: f0v03g$esh$1@sea.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Steve Crawford wrote:
>
> begin;
>
> select item-id, item-info
> from the-queue
> where available
> order by priority
> limit 1
> for update;
>
> update the-queue
> set status = 'assigned'
> where item-id = previously-selected-item-id;
>
> commit;
>

I do something similar in one of my apps:

BEGIN;

update the-queue
set status = 'assigned'
where available
order by priority
limit 1
returning item-id, item-info;

COMMIT;

This should be safer and faster.

Regards,
LL

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2007-04-28 10:20:45 Re: Some problem with warm standby server
Previous Message Heikki Linnakangas 2007-04-28 08:08:34 Re: When the locially dropped column is also physically dropped