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 B05059DC83C for ; Tue, 7 Feb 2006 11:49:32 -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 85635-09 for ; Tue, 7 Feb 2006 11:49:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 2C7D79DC81D for ; Tue, 7 Feb 2006 11:49:29 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 2571641457B; Tue, 7 Feb 2006 15:49:32 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id DD98D15EA4; Tue, 7 Feb 2006 15:49:31 +0000 (GMT) Message-ID: <43E8C18B.1010206@archonet.com> Date: Tue, 07 Feb 2006 15:49:31 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: Panos Kassianidis Cc: pgsql-sql@postgresql.org Subject: Re: Filtering data based on timestamp References: <43E8BF73.9000802@inaccessnetworks.com> In-Reply-To: <43E8BF73.9000802@inaccessnetworks.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.116 required=5 tests=[AWL=0.116] X-Spam-Score: 0.116 X-Spam-Level: X-Archive-Number: 200602/64 X-Sequence-Number: 24074 Panos Kassianidis wrote: > 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. You'll need to write an enhanced version of date_trunc() that can group timestamps into arbitrary units, e.g. my_date_trunc('... 12:34', 'm', 5) = '...12:30' Then you can group by your new value. -- Richard Huxton Archonet Ltd