From: Itai Zukerman <zukerman@math-hat.com>
To: pgsql-sql@postgresql.org
Subject: Re: Time Aggregates
Date: 02 Aug 2000 11:52:01 -0400
Message-ID: <87em47u0da.fsf@matt.w80.math-hat.com> (raw)
References: <87ittju6e7.fsf@matt.w80.math-hat.com>
<39883DD1.610A0954@alumni.caltech.edu>
> > SELECT symbol, date_trunc('minute', posted),
> > min(price), max(price), avg(price)
> > FROM trade
> > GROUP BY symbol, date_trunc('minute', posted);
Hmmm... I'm not sure how to go about doing this for, say, 5 minute
intervals. Basically, I want a function:
date_round( timestamp, timespan ) --> timestamp
that will round the timestamp to the "nearest" timespan interval,
counting back from, say, the current time.
date_round( '1/1/99 15:21', '5 minutes' ) --> '1/1/99 15:20'
if the current time is, say, 12:00. As I see it, this involves
1. calculating the interval between now and the timestamp;
2. rounding that interval to the nearest multiple of the supplied interval;
3. adding the rounded interval to the current time.
It's step 2 that I can't quite figure out. I'm thinking about using
date_part( 'epoch', ... ) and some arithmetic. Will that be OK? Has
anyone done this before?
-itai
PS. I'll also be happy if the function is called 'date_trunc' :)
PPS. I expect this query to be called much less often than inserts to
the table.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: zukerman@math-hat.com
Subject: Re: Time Aggregates
In-Reply-To: <87em47u0da.fsf@matt.w80.math-hat.com>
References: <87ittju6e7.fsf@matt.w80.math-hat.com> <39883DD1.610A0954@alumni.caltech.edu> <87em47u0da.fsf@matt.w80.math-hat.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