Re: Processing a work queue - Mailing list pgsql-general

From Lexington Luthor
Subject Re: Processing a work queue
Date
Msg-id f0v03g$esh$1@sea.gmane.org
Whole thread Raw
In response to Processing a work queue  (Steve Crawford <scrawford@pinpointresearch.com>)
List 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

pgsql-general by date:

Previous
From: Listmail
Date:
Subject: Re: Query in function not using index...
Next
From: "Simon Riggs"
Date:
Subject: Re: Some problem with warm standby server