Re: Updating a specific number of rows in pl/pgsql - Mailing list pgsql-sql

From D'Arcy J.M. Cain
Subject Re: Updating a specific number of rows in pl/pgsql
Date
Msg-id 20090811062503.86993bf6.darcy@druid.net
Whole thread Raw
In response to Updating a specific number of rows in pl/pgsql  ("Peter Headland" <pheadland@actuate.com>)
Responses Re: Updating a specific number of rows in pl/pgsql  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: Updating a specific number of rows in pl/pgsql  ("Peter Headland" <pheadland@actuate.com>)
List pgsql-sql
On Mon, 10 Aug 2009 17:52:36 -0700
"Peter Headland" <pheadland@actuate.com> wrote:
> I can get the rows I want to update like this:
> 
>   SELECT *
>    FROM queue
>    WHERE id = p_queue_id
>    ORDER BY rank
>    LIMIT p_number_of_items;
> 
> Of course, there may not be p_number_of_items available in the queue.
> 
> I want to update all the rows in the cursor in the same way:
> 
>   UPDATE queue SET assigned = TRUE;

Assuming that there is a unique identifier on queue, let's call it
queue_id, you should be able to do something like this:
 UPDATE queue SET assigned = TRUE WHERE queue_id IN (SELECT queue_id   FROM queue   WHERE id = p_queue_id   ORDER BY
rank  LIMIT p_number_of_items);
 

-- 
D'Arcy J.M. Cain <darcy@druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.


pgsql-sql by date:

Previous
From: Jamie Tufnell
Date:
Subject: Determining logically unique entities across many partially complete rows where at least one column matches
Next
From: Pavel Stehule
Date:
Subject: Re: Updating a specific number of rows in pl/pgsql