Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id DD19F1A5B07B for ; Thu, 9 Feb 2012 08:02:03 -0400 (AST) Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RvShL-0005Pw-BM for pgsql-sql@postgresql.org; Thu, 09 Feb 2012 12:02:02 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1RvSh5-0007ue-DQ for pgsql-sql@postgresql.org; Thu, 09 Feb 2012 13:01:43 +0100 Received: from ip-118-90-57-128.xdsl.xnet.co.nz ([118.90.57.128]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 09 Feb 2012 13:01:43 +0100 Received: from jasen by ip-118-90-57-128.xdsl.xnet.co.nz with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 09 Feb 2012 13:01:43 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Jasen Betts Subject: Re: time interval math Date: 9 Feb 2012 11:36:57 GMT Organization: Dis (not Dat) Organisation Lines: 29 Message-ID: References: <032001cce69c$767bc010$63734030$@com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ip-118-90-57-128.xdsl.xnet.co.nz X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-18 (Linux) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/27 X-Sequence-Number: 36320 On 2012-02-08, Edward W. Rouse wrote: > I'm still working on getting this to work, but the summary is this: > > I am getting several (many) intervals of hour, minutes and seconds. I need a > sum of the absolute value these intervals, similar to the SUM(ABS()) > function for numbers; and I need to divide this sum by an integer (bigint). > Getting the intervals is no problem, but I can't find built in functions for > the rest. Currently on 8.3, want to upgrade to 9.x but I can't until this is > finished. the operation abs() is meaninless on the type interval eg: what is abs( '1 month - 32 days + 24 hours'::interval ) howevwer since all your intervals are in seconds (postgres pretends that all hours are 3600 seconds long) converting to seconds is probably the best way to go. > Do these functions exist, or will I be forced to convert to seconds, do the > math and then convert back to hour-minute-second format (I am assuming from > current data that, after the divide, the result should be in the minute: > second range). Yeah, you need to do that, it's not hard, select ( sum(abs(extract('epoch' from YOUR_INTERVAL ))) / SOMETHING ) * '1s'::interval from ... -- ⚂⚃ 100% natural