Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 0ED37632C16 for ; Tue, 11 Aug 2009 07:25:20 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 70145-07 for ; Tue, 11 Aug 2009 10:25:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.vex.net (smaug.vex.net [208.76.104.132]) by mail.postgresql.org (Postfix) with ESMTP id 5EAD16321A5 for ; Tue, 11 Aug 2009 07:25:07 -0300 (ADT) Received: from dilbert (dilbert.druid.net [207.35.13.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.vex.net (Postfix) with ESMTPSA id 6AEB61706D; Tue, 11 Aug 2009 06:25:03 -0400 (EDT) Date: Tue, 11 Aug 2009 06:25:03 -0400 From: "D'Arcy J.M. Cain" To: "Peter Headland" Cc: Subject: Re: Updating a specific number of rows in pl/pgsql Message-Id: <20090811062503.86993bf6.darcy@druid.net> In-Reply-To: <71F491F5DA99604A80DE49424BF3D02B0C7290CA@exchange8.actuate.com> References: <71F491F5DA99604A80DE49424BF3D02B0C7290CA@exchange8.actuate.com> X-Mailer: Sylpheed 2.6.0 (GTK+ 2.16.1; i386-portbld-freebsd7.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.299 tagged_above=-10 required=5 tests=AWL=1.300, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200908/41 X-Sequence-Number: 32950 On Mon, 10 Aug 2009 17:52:36 -0700 "Peter Headland" 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 | 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.