Re: Time Aggregates - Mailing list pgsql-sql

From Thomas Lockhart
Subject Re: Time Aggregates
Date
Msg-id 39883DD1.610A0954@alumni.caltech.edu
Whole thread Raw
In response to Time Aggregates  (Itai Zukerman <zukerman@math-hat.com>)
List pgsql-sql
> I'm currently doing this:
>   SELECT symbol, date_trunc('minute', posted),
>          min(price), max(price), avg(price)
>   FROM trade
>   GROUP BY symbol, date_trunc('minute', posted);
> to get a list of minute-averages of trade prices.  I get the feeling
> that this is bad form, that I should be doing this some other way.  Is
> that the case?

Looks OK to me. If you are doing this *a lot* (i.e. many more queries
than inserts), then you might want to set up another column which
contains date_trunc('minute',posted) to avoid the calculation. Something
like
 create table trade (   symbol text,   posted timestamp,   price integer,   mpost  timestamp )

then define a rule to update mpost when posted gets set (haven't done
that part).
                   - Thomas


pgsql-sql by date:

Previous
From: Itai Zukerman
Date:
Subject: Time Aggregates
Next
From: Itai Zukerman
Date:
Subject: Re: Time Aggregates