Re: sum of a time column

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: arief# <arief_m_utama(at)telkomsel(dot)co(dot)id>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: sum of a time column
Date: 2004-03-05 15:01:08
Message-ID: 6993.1078498868@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

arief# <arief_m_utama(at)telkomsel(dot)co(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message beer 2004-03-05 15:06:27 Re: Trigger Update Issue
Previous Message Bruce Momjian 2004-03-05 14:56:01 Re: REFERENCES error message complaint, suggestion