X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5A0FC9DC85F for ; Thu, 26 Jan 2006 08:46:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 85614-01 for ; Thu, 26 Jan 2006 08:46:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from 137086.vserver.de (vs137086.vserver.de [62.75.137.86]) by postgresql.org (Postfix) with ESMTP id 8AC329DC82A for ; Thu, 26 Jan 2006 08:46:03 -0400 (AST) Received: from a-kretschmer.de (p54B3B358.dip0.t-ipconnect.de [84.179.179.88]) (authenticated bits=0) by 137086.vserver.de (8.12.8/8.12.8) with ESMTP id k0QCk49l021029 for ; Thu, 26 Jan 2006 13:46:06 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.60) (envelope-from ) id 1F26Vo-0004ap-OW for pgsql-sql@postgresql.org; Thu, 26 Jan 2006 13:46:04 +0100 Date: Thu, 26 Jan 2006 13:46:04 +0100 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: question with times and intervals Message-ID: <20060126124604.GA15790@KanotixBox> References: <20060126115816.GA9924@webserv.wug-glas.de> <43D8BBE7.4050108@archonet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <43D8BBE7.4050108@archonet.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: mutt-ng 1.5.9i (Linux) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.117 required=5 tests=[AWL=0.117] X-Spam-Score: 0.117 X-Spam-Level: X-Archive-Number: 200601/182 X-Sequence-Number: 23971 Richard Huxton 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°