Re: Grouping logs by ip and time

From: Ascarabina <ascarabina(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Grouping logs by ip and time
Date: 2011-11-08 19:00:45
Message-ID: 4EB97C5D.6030800@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Would something like this work? -
>
> select ip, max("time") - min("time") as session_duration
> from log_table
> group by ip;

I don't think this is the right way to do. This is based on ip address,
so if
- client connect diffrent times with same ip
- client has sime ip but he made another action on other day.
you will have a wrong results.

You should save also the session id and group by sesion id not ip.
Ex. :
Table
------------------
log_type text,
date date,
"time" time without time zone,
ip inet session_id text -- you can use maybe foreign tables ?

SQL ( Same as Raynold's but groups session ids)
-------------------
select ip, max("time") - min("time") as session_duration
from log_table
group by session_id;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alex Thurlow 2011-11-08 19:15:26 Re: Grouping logs by ip and time
Previous Message John R Pierce 2011-11-08 18:57:36 Re: Grouping logs by ip and time