pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: D'Arcy J.M. Cain <darcy@druid.net>
To: Peter Headland <pheadland@actuate.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Updating a specific number of rows in pl/pgsql
Date: Tue, 11 Aug 2009 06:25:03 -0400
Message-ID: <20090811062503.86993bf6.darcy@druid.net> (raw)
In-Reply-To: <71F491F5DA99604A80DE49424BF3D02B0C7290CA@exchange8.actuate.com>
References: <71F491F5DA99604A80DE49424BF3D02B0C7290CA@exchange8.actuate.com>

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.



view thread (8+ messages)  latest in thread

Message-ID: <20090811062503.86993bf6.darcy@druid.net>
Permalink:  ../20090811062503.86993bf6.darcy@druid.net/
Also on:    postgresql.org/message-id/20090811062503.86993bf6.darcy@druid.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: darcy@druid.net, pheadland@actuate.com
  Subject: Re: Updating a specific number of rows in pl/pgsql
  In-Reply-To: <20090811062503.86993bf6.darcy@druid.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox