Re: avg() for timestamp

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: avg() for timestamp
Дата
Msg-id 3550.1078757578@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: avg() for timestamp  (Bruno Wolff III <bruno@wolff.to>)
Список 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 по дате отправления:

Предыдущее
От: Shachar Shemesh
Дата:
Сообщение: one byte data type
Следующее
От: GeGeZ
Дата:
Сообщение: question about API to b-tree in PG