pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Panos Kassianidis <pkas@inaccessnetworks.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Filtering data based on timestamp
Date: Tue, 07 Feb 2006 15:49:31 +0000
Message-ID: <43E8C18B.1010206@archonet.com> (raw)
In-Reply-To: <43E8BF73.9000802@inaccessnetworks.com>
References: <43E8BF73.9000802@inaccessnetworks.com>

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



view thread (3+ messages)  latest in thread

Message-ID: <43E8C18B.1010206@archonet.com>
Permalink:  ../43E8C18B.1010206@archonet.com/
Also on:    postgresql.org/message-id/43E8C18B.1010206@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, pkas@inaccessnetworks.com
  Subject: Re: Filtering data based on timestamp
  In-Reply-To: <43E8C18B.1010206@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox