Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 842F69FB2A6 for ; Fri, 13 Oct 2006 08:48:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 15108-01 for ; Fri, 13 Oct 2006 11:48:15 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (mail.logix-tt.com [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id 00AB49FB2FA for ; Fri, 13 Oct 2006 08:48:14 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (84-72-188-217.dclient.hispeed.ch [84.72.188.217]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id B132465977; Fri, 13 Oct 2006 13:50:43 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id A3DEE18148BBF; Fri, 13 Oct 2006 13:48:12 +0200 (CEST) Message-ID: <452F7CFC.50009@logix-tt.com> Date: Fri, 13 Oct 2006 13:48:12 +0200 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Thunderbird 1.5.0.7 (X11/20060927) MIME-Version: 1.0 To: Daniel Drotos Cc: pgsql-sql@postgresql.org Subject: Re: deleting rows in specific order References: <452CE81A.5010001@logix-tt.com> In-Reply-To: X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/127 X-Sequence-Number: 26516 Hi, Daniel, Daniel Drotos wrote: >> What is it that you're trying to achieve with the ordered delete? Maybe >> there's a better way to solve your underlying problem. > > I've a table which has a field for some info (number) and a date field > (insertion date) and others. > > After inserting new rows into this table, very old rows are going to be > deleted. But value of deleted info should be remembered somehow, so > there is a trigger on delete which keeps sum of the deleted info values > in a separate table. This makes the application happy. > > Trigger's algorithm is a little bit more dificult which I would be able > to simplify if rows are deleted in date order. Ah, I see. I don't know exactly what you're doing here, but at least for a sum, the order of summed values is not relevant. And due to the transaction system, other applications won't see inconsistent intermediate states, as the whole DELETE run and all trigger calls are part of the same transaction. > Now I'm doing it in a plpgsql function using a `for in select loop' to > delete rows one by one. I'm afraid that this is the only solution if you can't simplify the trigger by other means. HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in Europe! www.ffii.org www.nosoftwarepatents.org