Re: sum of a time column

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: sum of a time column
Дата
Msg-id 6993.1078498868@sss.pgh.pa.us
обсуждение исходный текст
Ответ на sum of a time column  (arief# <arief_m_utama@telkomsel.co.id>)
Список pgsql-general
arief# <arief_m_utama@telkomsel.co.id> writes:
> Suppose I have a field in my table that's called duration with type
> 'time without timezone'. How do I do sum on this field based on another
> field let say called dateofevent?

> SQL: SELECT SUM(duration) FROM durtable GROUP BY dateofevent;
> ERROR:  Unable to select an aggregate function sum(time without time
> zone)

There are neither addition nor SUM() operations for the time type,
because it is not logically sensible to add two times of day.

It seems that you may be using the wrong datatype --- perhaps the way
you are using the field is really as an interval?

If you're really intent on using the time type here, you can cast it
to interval:
    SELECT SUM(duration::interval) FROM ...

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Trigger Update Issue
Следующее
От: Tom Lane
Дата:
Сообщение: Re: relocatable binary distribution