473,383 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

sum of a time column

Dear all,
I'm sorry if this sounds stupid or have been talked about before.

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;

gives me:

ERROR: Unable to select an aggregate function sum(time without time
zone)

Is this because of me still using PostgreSQL version 7.2.1 from Debian
Woody? Or some other stupidity?
TIA, Regards.
-arief


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #1
3 8893
Hello,

you can sum only interval type

create type x (a inteval);

testdb011=> insert into x values ('1 day'::interval);
INSERT 18871 1
testdb011=> insert into x values ('1 day'::interval);
INSERT 18872 1
testdb011=> insert into x values ('1 day'::interval);
INSERT 18873 1
testdb011=> insert into x values ('1 day'::interval);
INSERT 18874 1
testdb011=> insert into x values ('1 day'::interval);
INSERT 18875 1
testdb011=> insert into x values ('1 day'::interval);
testdb011=> select sum(i) from x;
sum
--------
6 days
regards
Pavel Stehule

On Fri, 5 Mar 2004, arief# wrote:
Dear all,
I'm sorry if this sounds stupid or have been talked about before.

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;

gives me:

ERROR: Unable to select an aggregate function sum(time without time
zone)

Is this because of me still using PostgreSQL version 7.2.1 from Debian
Woody? Or some other stupidity?
TIA, Regards.
-arief


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #2
arief# <ar***********@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

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #3
On Fri, 5 Mar 2004, arief# wrote:
Dear all,
I'm sorry if this sounds stupid or have been talked about before.

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;

gives me:

ERROR: Unable to select an aggregate function sum(time without time
zone)

Is this because of me still using PostgreSQL version 7.2.1 from Debian
Woody? Or some other stupidity?


No, there's just no logical way to add dates. If you want to find the
total number of days those dates are after a certain date, you could do
something like:

select sum('2005-01-01 00:00:00'-dt) from table;
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lauren Quantrell | last post by:
I have two columns in a table: StartDate DateTime and StartTime DateTime. The StartDate column holds a value such as 07/16/2004 The StartTime column holds a value such as 3:00:00 PM I want to...
6
by: teddysnips | last post by:
I have a table called WorkItem. It models a chunk of work done during a working day. It has two columns that I'm interested in: Start (smalldatetime) - the TIME the work block is begun...
1
by: John Feeley | last post by:
am tring to add a number of years to a dob. im doing this by adding my date+years*365.26 I get a string of numbers. I then convert the number in the next column to actual date again. I'm getting...
4
by: karunakar | last post by:
Hi All I was poplating Datagrid Datagrid has one of the column showing datetime field format iam showing DATE here not Necessary to populate the Time Frame Even my datebase column also...
4
by: PawelR | last post by:
Hello Everyone Sorry but my English is very littel. In my application I use Crystal Reports. On report I have (in one row) to dateTime. How in 3th column calculate difftime beetwen this value and...
6
by: Sebastian Santacroce | last post by:
How do I get a datetime field from a database to show just time in the datagrid. The default just shows date. Thank you Sebastian
9
by: Hemant Shah | last post by:
How do I find out when the table was modified? When I look at syscat.tables it only lists creation time. -- Hemant Shah /"\ ASCII ribbon campaign E-mail:...
6
by: fniles | last post by:
I am using VB.NET 2003 and SQL Server 2000. I have a table with a datetime column type. When inserting into the table for that column, I set it to Date.Now.ToString("T") , which is something like...
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
0
by: chromis | last post by:
Hi, I've recently been porting a little php / mysql script over to asp / mssql and I've got issues with the timestamp data type. With mysql i could easily insert 01:01:01 into the timestamp...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.