interval questions - Mailing list pgsql-general

From Michael Blakeley
Subject interval questions
Date
Msg-id p04320421b55cb1ee3b65@blakeley.com
Whole thread Raw
Responses Re: interval questions
Re: interval questions
List pgsql-general
I hope someone on the list can suggest a solution for me - given a table like

CREATE TABLE EVENTS( stamp date, id varchar(16), event varchar(128) );

I'm trying to find the average age of the records. I've gotten as far as:
    SELECT DISTINCT ON(id) age(stamp) FROM EVENTS;

Now, I need the DISTINCT ON(id), but that means I can't simply avg() the age:
    ERROR:  Attribute events.id must be GROUPed or used in an
aggregate function

Can anyone suggest a solution? I could do the averaging myself,
except that the output is non-trivial to parse:
     7 mons 6 10:29
     2 mons 30 07:43:38
     3 mons 4 09:50:56
(To be accurate, my code has to get the days in each month right,
etc., and it feels like I'm reinventing the wheel there.)

Thanks in advance for any suggestions.

-- Mike

pgsql-general by date:

Previous
From: Ron Chmara
Date:
Subject: Re: PostgreSQL article in LinuxWorld
Next
From: Tom Lane
Date:
Subject: Re: query optimiser changes 6.5->7.0