Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id B73581337B64 for ; Tue, 23 Nov 2010 11:32:08 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 25976-03 for ; Tue, 23 Nov 2010 15:32:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id C30831336B42 for ; Tue, 23 Nov 2010 11:32:00 -0400 (AST) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id W4GBNQ8J; Tue, 23 Nov 2010 15:31:59 -0000 Message-ID: <5678C0F3BD5E48F587D8065C9C38BAA9@marktestcr.marktest.pt> From: "Oliveiros d'Azevedo Cristina" To: "Louis-David Mitterrand" , References: <20101123151918.GA22094@apartia.fr> Subject: Re: "compressing" consecutive values into one Date: Tue, 23 Nov 2010 15:31:59 -0000 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.428 tagged_above=-5 required=5 tests=BAYES_40=-0.001, STOX_REPLY_TYPE=0.439, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/49 X-Sequence-Number: 34787 Salut, Louis-David, Can you please state the columns belonging to price table and give a concrete example? Say, data before and data after you want to do? Thank you A bien-tôt, Oliveiros ----- Original Message ----- From: "Louis-David Mitterrand" To: Sent: Tuesday, November 23, 2010 3:19 PM Subject: [SQL] "compressing" consecutive values into one > 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, > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql