Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 16E1E1A5B07E for ; Thu, 9 Feb 2012 10:32:00 -0400 (AST) Received: from smtp.comsquared.com ([209.155.237.140]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RvV2T-00052a-4w for pgsql-sql@postgresql.org; Thu, 09 Feb 2012 14:31:59 +0000 Received: from mdpserv.comsquared.com (mdpserv [10.82.40.1]) by smtp.comsquared.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id q19EVbCH006343 for ; Thu, 9 Feb 2012 09:31:40 -0500 (EST) Received: from erouse052008 ([10.82.60.61]) by mdpserv.comsquared.com (8.13.6+Sun/8.13.6) with ESMTP id q19EVa0b006203 for ; Thu, 9 Feb 2012 09:31:37 -0500 (EST) From: "Edward W. Rouse" To: References: <032001cce69c$767bc010$63734030$@com> In-Reply-To: Subject: Re: time interval math Date: Thu, 9 Feb 2012 09:31:34 -0500 Message-ID: <034901cce737$86614180$9323c480$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcznIrbgpfT1jkH3T8e6BWCZjt9KOgAFH7AQ Content-Language: en-us X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/28 X-Sequence-Number: 36321 > -----Original Message----- > From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql- > owner@postgresql.org] On Behalf Of Jasen Betts > Sent: Thursday, February 09, 2012 6:37 AM > To: pgsql-sql@postgresql.org > Subject: Re: [SQL] time interval math >=20 > 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. >=20 > the operation abs() is meaninless on the type interval > eg: what is abs( '1 month - 32 days + 24 hours'::interval ) If you need to add 30 intervals together, then +- is not meaningless.=20 >=20 > 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. >=20 > > 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). >=20 > Yeah, you need to do that, it's not hard, >=20 > select ( sum(abs(extract('epoch' from YOUR_INTERVAL ))) / SOMETHING ) = * > '1s'::interval > from ... >=20 > -- > =E2=9A=82=E2=9A=83 100% natural >=20 >=20 > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql