Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 88B2A1337B90 for ; Tue, 23 Nov 2010 11:19:27 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 38679-02 for ; Tue, 23 Nov 2010 15:19:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from zenon.apartia.fr (zenon.apartia.fr [82.66.93.83]) by mail.postgresql.org (Postfix) with ESMTP id 050501337B81 for ; Tue, 23 Nov 2010 11:19:19 -0400 (AST) Received: from sylla.apartia.fr (sylla.apartia.fr [10.0.3.3]) by zenon.apartia.fr (Postfix) with ESMTP id 3C979424FD025 for ; Tue, 23 Nov 2010 16:19:19 +0100 (CET) Received: by sylla.apartia.fr (Postfix, from userid 1000) id 22E39402734AE; Tue, 23 Nov 2010 16:19:19 +0100 (CET) Date: Tue, 23 Nov 2010 16:19:19 +0100 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: "compressing" consecutive values into one Message-ID: <20101123151918.GA22094@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201011/48 X-Sequence-Number: 34786 Hi, On time series price data I'm trying to remove consecutive identical prices and keep only the latest. I tried: delete from price where id_price in (select t.id_price2 from (select first_value(p.id_price) over w as id_price1, nth_value(p.id_price, 2) over w as id_price2, first_value(p.price) over w as price1, nth_value(p.price,2) over w as price2 from price p window w as (partition by p.id_rate,p.id_cabin_category,p.id_cruise order by p.id_price desc rows between unbounded preceding and unbounded following)) as t where price1 = price2); and it mostly works but I have to do several runs to completely eliminate identical consecutive prices. Is there a better, one-pass, way? Thanks,