Re: Grouping logs by ip and time - Mailing list pgsql-general

From Alex Thurlow
Subject Re: Grouping logs by ip and time
Date
Msg-id 4EB97FCE.3060505@blastro.com
Whole thread Raw
In response to Re: Grouping logs by ip and time  (Ascarabina <ascarabina@gmail.com>)
List pgsql-general
On 11/8/2011 1:00 PM, Ascarabina wrote:
>> 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;
>
Thanks for the responses guys.  I guess I'll need to figure out how to
add a session ID if I'm going to do this.

     -Alex

pgsql-general by date:

Previous
From: Ascarabina
Date:
Subject: Re: Grouping logs by ip and time
Next
From: Martín Marqués
Date:
Subject: Re: Replication Across Two Servers?