X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6B2809DC81D for ; Tue, 7 Feb 2006 11:41:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83580-07 for ; Tue, 7 Feb 2006 11:41:11 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 6F2379DC814 for ; Tue, 7 Feb 2006 11:41:04 -0400 (AST) Received: from inaccessnetworks.com (node3.inaccessnetworks.com [212.205.200.118]) by svr4.postgresql.org (Postfix) with ESMTP id 557C55AF09A for ; Tue, 7 Feb 2006 15:41:06 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by inaccessnetworks.com (8.13.5/8.13.5) with ESMTP id k17FexLt021211 for ; Tue, 7 Feb 2006 17:40:59 +0200 Received: from inaccessnetworks.com ([127.0.0.1]) by localhost (host11.inaccessnetworks.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 20395-19 for ; Tue, 7 Feb 2006 17:40:57 +0200 (EET) Received: from priv.inaccessnetworks.com (orion.priv.inaccessnetworks.com [192.168.1.2]) by inaccessnetworks.com (8.13.5/8.13.5) with ESMTP id k17FeqFb021204 for ; Tue, 7 Feb 2006 17:40:52 +0200 Received: from [192.168.1.151] (pkas@[192.168.1.151]) by priv.inaccessnetworks.com (8.12.1/8.12.1) with ESMTP id k17FeqCm014853 for ; Tue, 7 Feb 2006 17:40:52 +0200 Message-ID: <43E8BF73.9000802@inaccessnetworks.com> Date: Tue, 07 Feb 2006 17:40:35 +0200 From: Panos Kassianidis User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Filtering data based on timestamp Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-2.2.0 (20041102) + Maia Mailguard 1.0.0 RC5 (Debian) at inaccessnetworks.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200602/63 X-Sequence-Number: 24073 Hello everybody, I am building a data logging application and I am facing the following problem. I have a table which holds timestamp-value pairs for a recorded variable. I would like to be able to select a range of values between a starting and an ending timestamp but also specify an interval over which values should be averaged. For example let's say I have 180 values recorded over the last 3 hours (1 per minute) and I would like to retrieve values recorded in the last 2 hours but with an interval of 5 minutes, which means that my query should return one tuple for every 5 tuples in the table and the value of this tuple should be an average of 5 values. Does anyone have any clue how I can make this query? I have though about somehow grouping the tuples with group by and use the AVG function but the tuples don't have anything in common to be grouped by. Thank you very much in advance. Panos