From: | Raymond O'Donnell <rod(at)iol(dot)ie> |
---|---|
To: | rod(at)iol(dot)ie |
Cc: | Alex Thurlow <alex-reports(at)blastro(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Grouping logs by ip and time |
Date: | 2011-11-08 18:54:48 |
Message-ID: | 4EB97AF8.7090709@iol.ie |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 08/11/2011 18:48, Raymond O'Donnell wrote:
> On 08/11/2011 17:59, Alex Thurlow wrote:
>> Hello all,
>> I have a table which stores action logs from users. It looks
>> something like this:
>> log_type text,
>> date date,
>> "time" time without time zone,
>> ip inet
>
> [snip]
>
>> What I'd like to do is be able to group these logs by sessions based on
>> the IP and the time range so I can figure out the time taken between
>> each action.
>
> Would something like this work? -
>
> select ip, max("time") - min("time") as session_duration
> from log_table
> group by ip;
>
> This doesn't take the date into account - what happens if the session
> spans midnight? You can get around this by using a timestamp column
> instead of separate date and time.
Whoops - just re-read your email, and realised that you're looking for
the time between actions; the above just gives you the total duration of
the session from each IP address.
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie
From | Date | Subject | |
---|---|---|---|
Next Message | John R Pierce | 2011-11-08 18:57:36 | Re: Grouping logs by ip and time |
Previous Message | Raymond O'Donnell | 2011-11-08 18:48:52 | Re: Grouping logs by ip and time |