Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id A28D21337B3E for ; Tue, 16 Nov 2010 07:24:29 -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 73247-04 for ; Tue, 16 Nov 2010 11:24:23 +0000 (UTC) X-Greylist: delayed 00:05:35.61851 by SQLgrey-1.7.6 Received: from adonis.tweakers.net (adonis.tweakers.net [213.239.154.11]) by mail.postgresql.org (Postfix) with ESMTP id 33A041336B42 for ; Tue, 16 Nov 2010 07:24:22 -0400 (AST) Received: from groupware.tweakers.net (groupware.tweakers.net [212.41.134.181]) by adonis.tweakers.net (Postfix) with ESMTPSA id 111A620AF8 for ; Tue, 16 Nov 2010 12:18:45 +0100 (CET) X-MDAV-Processed: groupware.tweakers.net, Tue, 16 Nov 2010 12:17:42 +0100 Received: from [10.75.99.57] by groupware.tweakers.net (Cipher TLSv1:RC4-MD5:128) (MDaemon PRO v10.0.5) with ESMTP id md50000291178.msg for ; Tue, 16 Nov 2010 12:17:42 +0100 X-Spam-Processed: groupware.tweakers.net, Tue, 16 Nov 2010 12:17:42 +0100 (not processed: spam filter heuristic analysis disabled) X-Return-Path: acmmailing@tweakers.net X-Envelope-From: acmmailing@tweakers.net X-MDaemon-Deliver-To: pgsql-performance@postgresql.org Message-ID: <4CE2688B.2050000@tweakers.net> Date: Tue, 16 Nov 2010 12:18:35 +0100 From: Arjen van der Meijden User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: best db schema for time series data? References: <20101116105055.GA26129@apartia.fr> In-Reply-To: <20101116105055.GA26129@apartia.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.6 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201011/261 X-Sequence-Number: 41285 On 16-11-2010 11:50, Louis-David Mitterrand wrote: > I have to collect lots of prices from web sites and keep track of their > changes. What is the best option? > > 1) one 'price' row per price change: > > create table price ( > id_price primary key, > id_product integer references product, > price integer > ); > > 2) a single 'price' row containing all the changes: > > create table price ( > id_price primary key, > id_product integer references product, > price integer[] -- prices are 'pushed' on this array as they change > ); > > Which is bound to give the best performance, knowing I will often need > to access the latest and next-to-latest prices? If you mostly need the last few prices, I'd definitaly go with the first aproach, its much cleaner. Besides, you can store a date/time per price, so you know when it changed. With the array-approach that's a bit harder to do. If you're concerned with performance, introduce some form of a materialized view for the most recent price of a product. Or reverse the entire process and make a "current price"-table and a "price history"-table. Best regards, Arjen