X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id AC6ED9FBCD9 for ; Fri, 25 Aug 2006 17:41:01 -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 67460-06 for ; Fri, 25 Aug 2006 20:40:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31810.mail.mud.yahoo.com (web31810.mail.mud.yahoo.com [68.142.207.73]) by postgresql.org (Postfix) with SMTP id 8D96C9FBCD7 for ; Fri, 25 Aug 2006 17:40:58 -0300 (ADT) Received: (qmail 31141 invoked by uid 60001); 25 Aug 2006 20:40:57 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=obu1pf3LwOdjtaJGCugmQc4TUWsl69yYPdgoKbSF30d8JUWgOfHUzOMSV2rtGC7fHq5WStCQeL1OdfDDiMBvQyiwkWIYP2LG7dU4mAQXGsfP+uF9KKdZmPM+uOVzC/6rV8CG7oVs5AOCmJkL4thZtNw6NS1O2qVb4pJ5dYtWx2c= ; Message-ID: <20060825204057.31139.qmail@web31810.mail.mud.yahoo.com> Received: from [63.203.180.122] by web31810.mail.mud.yahoo.com via HTTP; Fri, 25 Aug 2006 13:40:56 PDT Date: Fri, 25 Aug 2006 13:40:56 -0700 (PDT) From: Richard Broersma Jr Subject: Re: Best way to do this query.. To: Henry Ortega , pgsql-sql@postgresql.org In-Reply-To: <2bffcc330608251316g6ed00710u6e43b243800c6087@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.355 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS X-Spam-Level: *** X-Archive-Number: 200608/203 X-Sequence-Number: 26161 > I have the following: > > name effective tstamp rate > John 01-01-2006 2005-12-07 13:39:07.614945 115.00 > John 01-16-2006 2006-01-07 13:39:07.614945 125.00 > John 01-16-2006 2006-01-09 15:13:04.416935 1885.00 > > I want the output to be: > name effective end_date rate > John 01-01-2006 01-15-2006 115.00 > John 01-16-2006 1885.00 > > What is the best way to do this? This is on a huge table and what I > have right now is quite slow. Any ideas? I would assume that your data does not change after it is logged. If this is the case, maybe this part of your data model would actually be a good canidate for an OLAP data model. If this is not the direction your are enterested in moving, you could also reduce your query processing time by limiting the data ranges for your existing query to something for reasonable. Regards, Richard Broersma Jr.