Re: question with times and intervals

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: question with times and intervals
Date: 2006-01-26 12:46:04
Message-ID: 20060126124604.GA15790@KanotixBox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Richard Huxton <dev(at)archonet(dot)com> schrieb:

> Now (upper_time - lower_time) is the interval you want and summing them
> will give you your answer.
>
> Any help?

Yes, thanks.

But, i remember a little function that i wrote in the past:
http://a-kretschmer.de/tools/time_intersect.sql

And now i have a solution (i hope):

test=# select id, status,
test-# sum((time_intersect(t_start, t_end, '2006/01/21 00:00:00'::timestamptz, '2006/01/22 23:59:59'::timestamptz)).t2 -
test(# (time_intersect(t_start, t_end, '2006/01/21 00:00:00+1'::timestamptz, '2006/01/22 23:59:59+1'::timestamptz)).t1)
test-# from status_log
test-# where (t_start, t_end) overlaps ('2006/01/21 00:00:00+1'::timestamptz, '2006/01/22 23:59:59'::timestamptz)
test-# group by id, status
test-# order by 1,2;
id | status | sum
----+--------+----------
1 | 1 | 32:00:00
1 | 2 | 15:59:59
(2 rows)

Okay, now i can write a function similar above which returns the
interval and the i can sum() this.

Thanks, Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Markus Schaber 2006-01-26 12:51:27 Re: Changing the transaction isolation level within the stored
Previous Message Richard Huxton 2006-01-26 12:09:11 Re: question with times and intervals