Re: avg() for timestamp - Mailing list pgsql-hackers

From Tom Lane
Subject Re: avg() for timestamp
Date
Msg-id 3550.1078757578@sss.pgh.pa.us
Whole thread Raw
In response to Re: avg() for timestamp  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-hackers
Bruno Wolff III <bruno@wolff.to> writes:
>   Neil Conway <neilc@samurai.com> wrote:
>> It seems to me the following should Just Work:
>> nconway=# select avg(a) from t1;
>> ERROR:  function avg(timestamp without time zone) does not exist

> While there is a way to calculate an average timestamp, I don't think
> there is an easy way to do this automatically with say a polymorphic
> aggregate. You need to know that there is a related type interval that
> can be used to keep track of differences in timestamps and that can be
> added back to a timestamp at the end.

Given that this would be done with C code, I doubt we'd go to the
trouble of implementing it that way.  We'd just cheat: add up the 
numeric values of the timestamps and divide at the end.  float8
makes a perfectly fine accumulator ;-)
        regards, tom lane


pgsql-hackers by date:

Previous
From: Shachar Shemesh
Date:
Subject: one byte data type
Next
From: GeGeZ
Date:
Subject: question about API to b-tree in PG