pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-sql@postgresql.org
Subject: Re: question with times and intervals
Date: Thu, 26 Jan 2006 13:46:04 +0100
Message-ID: <20060126124604.GA15790@KanotixBox> (raw)
In-Reply-To: <43D8BBE7.4050108@archonet.com>
References: <20060126115816.GA9924@webserv.wug-glas.de>
	<43D8BBE7.4050108@archonet.com>

Richard Huxton <dev@archonet.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°



view thread (3+ messages)

Message-ID: <20060126124604.GA15790@KanotixBox>
Permalink:  ../20060126124604.GA15790@KanotixBox/
Also on:    postgresql.org/message-id/20060126124604.GA15790@KanotixBox

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: akretschmer@spamfence.net
  Subject: Re: question with times and intervals
  In-Reply-To: <20060126124604.GA15790@KanotixBox>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox