Re: Aggregate time data on half hour interval

From: Lars <lars(at)sscsinc(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Aggregate time data on half hour interval
Date: 2000-07-20 05:59:53
Message-ID: Pine.BSF.4.10.10007192254020.9376-100000@maximillion.sscsinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

It may be ugly, but it sure works! Here is my query:

SELECT Date, interval(trunc(date_part('epoch', time)/1800) * 1800) AS
HALFHOUR, SUM(Data)
FROM Table
GROUP BY Date, HALFHOUR;

This seems to work great, and I don't see any performance hit either.
Thanks,

-Lars

On Thu, 20 Jul 2000, Tom Lane wrote:

> Lars <lars(at)sscsinc(dot)com> writes:
> > What I would like to do though is aggregate by each half hour or maybe
> > even 20 minutes. Does anyone know a good way to do this?
>
> I don't have a *good* answer, but a brute-force way is
>
> * convert timestamp to integer seconds with date_part('epoch', foo)
> * round to a multiple of desired time interval
> * convert back to timestamp for display via timestamp()
>
> In the long run it seems like date_trunc ought to be more flexible
> than it is...
>
> regards, tom lane
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Lockhart 2000-07-20 06:00:27 Re: Aggregate time data on half hour interval
Previous Message Tom Lane 2000-07-20 05:20:51 Re: Aggregate time data on half hour interval