Re: trying to summarize into a new table by time...

From: Alex Pilosov <alex(at)pilosoft(dot)com>
To: Larry Rosenman <ler(at)lerctr(dot)org>
Cc: PostgreSQL SQL List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: trying to summarize into a new table by time...
Date: 2001-06-02 18:14:38
Message-ID: Pine.BSO.4.10.10106021300380.17529-100000@spider.pilosoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Funny, I just yesterday wrote the same exact thing (ip/asn accounting
based on netflow)

The problem is to iterate over range, which SQL doesn't like to do, unless
given an explicit range table. Thus, there are possible solutions.

a) do it like this:
insert into traffic_summary
...
group by date_part('epoch',early)/60/60/2

(assuming 2-hour aggregation interval)

However, using this method, you won't get any data in traffic_summary
when there was no traffic. If you want that, use...

b) have an explicit table traffic_periods(period_start timestamp,
period_end timestamp), prepopulated with data, and then doing

insert ...
select ...
from traffic t,traffic_periods tp
where t.early between period_start and period_end
group by tp.oid

On Sat, 2 Jun 2001, Larry Rosenman wrote:

> insert into traffic_summary
> select asn,protocol,
> cast(sum(pkts_src) as float) as pkts_src,
> cast(sum(pkts_dst) as float) as pkts_dst,
> cast(sum(bytes_src) as float) as bytes_src,
> cast(sum(bytes_dst) as float) as bytes_dst,
> cast(sum(secs_src) as float) as secs_src,
> cast(sum(secs_dst) as float) as secs_dst,
> min(early) as early,
> max(late) as late
> from traffic
> where early >= '2001-01-01 00:00:00' and
> early <= '2001-01-02 05:59:59'
> GROUP BY asn,protocol;
>
> BUT, I'm wondering if there is an easy way to generate the obvious
> where clauses automatically?
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mario Bittencourt 2001-06-02 22:49:55 Tutorial : using foreign keys, retrictions etc
Previous Message Clayton Cottingham aka drfrog 2001-06-02 17:27:30 help with a function