From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Kevin Burke <burke(at)shyp(dot)com> |
Cc: | "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org> |
Subject: | Re: UPDATE grabs multiple rows when it seems like it should only grab one |
Date: | 2016-04-22 23:06:00 |
Message-ID: | CAKFQuwbNXj0ygV2WVrY6-GtJpdY+tgr5Rzeo8YBL9=byZxOYkw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Fri, Apr 22, 2016 at 3:56 PM, Kevin Burke <burke(at)shyp(dot)com> wrote:
> Hi,
> I'm trying to write a job queue that grabs one job at a time from the
> queue. I expect that the following query should update a maximum of one row
> in the table:
>
> UPDATE queued_jobs
> SET status='in-progress',
> updated_at=now()
> FROM (
> SELECT id AS inner_id
> FROM queued_jobs
> WHERE status='queued'
> AND name = $1
> AND run_after <= now()
> LIMIT 1
> FOR UPDATE
> ) find_job
> WHERE queued_jobs.id = find_job.inner_id
> AND status='queued'
> RETURNING id,
> name,
> attempts,
> run_after,
> expires_at,
> status,
> data,
> created_at,
> updated_at
>
>
Can you alter this to do:
RETURNING ctid, id, etc....
And then show the records that are returned?
No promises it will work....
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2016-04-22 23:09:47 | Re: UPDATE grabs multiple rows when it seems like it should only grab one |
Previous Message | Kevin Burke | 2016-04-22 23:01:11 | Re: UPDATE grabs multiple rows when it seems like it should only grab one |