Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id D5B6A6333F5 for ; Wed, 14 Apr 2010 11:55:37 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 45769-03 for ; Wed, 14 Apr 2010 14:55:26 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sargon.lncsa.com (mail.lncsa.com [213.215.28.11]) by mail.postgresql.org (Postfix) with ESMTP id 339AF633988 for ; Wed, 14 Apr 2010 11:54:38 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id A7A133022A4E for ; Wed, 14 Apr 2010 16:54:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at lncsa.com Received: from sargon.lncsa.com ([127.0.0.1]) by localhost (sargon.lncsa.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kvC8IHIPiyEg for ; Wed, 14 Apr 2010 16:54:35 +0200 (CEST) Received: from zenon.apartia.fr (zenon.apartia.fr [10.0.3.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "zenon.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by sargon.lncsa.com (Postfix) with ESMTP id 8943E3022A4D for ; Wed, 14 Apr 2010 16:54:35 +0200 (CEST) Received: from galba.apartia.fr (galba.apartia.fr [10.0.3.119]) by zenon.apartia.fr (Postfix) with ESMTP id 2DA515B93FA39 for ; Wed, 14 Apr 2010 16:54:35 +0200 (CEST) Received: by galba.apartia.fr (Postfix, from userid 1000) id CEB021D723; Wed, 14 Apr 2010 16:54:34 +0200 (CEST) Date: Wed, 14 Apr 2010 16:54:34 +0200 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: graphing time series data Message-ID: <20100414145434.GA13682@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.20 (2009-06-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201004/51 X-Sequence-Number: 33978 Hi, I have times series data in a 'price' table: price(id_price, price, id_product, created, modified) Prices are polled daily and a new 'price' row is created only if the price of id_product changes, else modified is updated to now(). Now, I'd like to make a graph of average prices per week, per id_product. As some prices don't vary much, distribution would not be ideal if I simply 'group by extract(week from p.modified)'. Ideally I'd generate_series() a list of weeks between min(p.created) and max(p.modified) and then average prices 'group by p.modified < week'. What would be the best way to tackle this? Thanks,