Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id AADF42E0085 for ; Tue, 13 May 2008 05:41:15 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 08900-05 for ; Tue, 13 May 2008 05:41:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smadev.internal.net (host3.dynacom.ondsl.gr [62.103.35.211]) by developer.postgresql.org (Postfix) with ESMTP id D96C62E0084 for ; Tue, 13 May 2008 05:41:10 -0300 (ADT) Received: from smadev.internal.net (localhost [127.0.0.1]) by smadev.internal.net (8.14.2/8.14.2) with ESMTP id m4D8f3bc097960; Tue, 13 May 2008 11:41:03 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) Received: from localhost (localhost [[UNIX: localhost]]) by smadev.internal.net (8.14.2/8.14.2/Submit) id m4D8f1EA097959; Tue, 13 May 2008 11:41:01 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: "Scott Marlowe" Subject: Re: how to get a number of seconds in some interval ? Date: Tue, 13 May 2008 11:41:00 +0300 User-Agent: KMail/1.9.7 Cc: pgsql-admin@postgresql.org, "Tom Lane" , "Julius Tuskenis" References: <482849B0.6050103@nsoft.lt> <200805130956.51872.achill@matrix.gatewaynet.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200805131141.01422.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/103 X-Sequence-Number: 29187 =CE=A3=CF=84=CE=B9=CF=82 Tuesday 13 May 2008 11:22:28 =CE=BF/=CE=B7 Scott M= arlowe =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: > On Tue, May 13, 2008 at 12:56 AM, Achilleas Mantzios > wrote: > > =D3=F4=E9=F2 Monday 12 May 2008 18:09:11 =EF/=E7 Tom Lane =DD=E3=F1=E1= =F8=E5: > >> Achilleas Mantzios writes: > >> > =D3=F4=E9=F2 Monday 12 May 2008 17:32:39 =EF/=E7 Julius Tuskenis =DD= =E3=F1=E1=F8=E5: > >> >> do you know why division of intervals was not implemented? As I see= it - > >> >> there should be an easy way to do so. '1 hour 30 minutes' / '1 hour= ' =3D > >> >> 1.5 .... Seems straight forward... > >> >> > >> > No idea why. However as you pose it,it makes sense. > >> > >> No, it doesn't really, because intervals contain multiple components. > >> What would you define as the result of > >> '1 month 1 hour' / '1 day' > >> bearing in mind that the number of days per month is not fixed, and > >> neither is the number of hours per day? > >> > > > > SELECT extract(epoch from '1 month'::interval)/(60*60*24) as "Days in 1= month interval"; > > Days in 1 month interval > > -------------------------- > > 30 > > (1 row) > > So it seems that the arbitary assumption of (1 month=3D30 days, and 1 d= ay =3D 24 hours) has already been made > > in the extract function. >=20 > True. But that's only because it doesn't have a date to work against. > If you run: >=20 > select '2007-02-01 12:00:00'::timestamp + '1 month'::interval; > you get: 2007-03-01 12:00:00 >=20 > If you run: > select '2007-03-01 12:00:00'::timestamp + '1 month'::interval; > you get: 2007-04-01 12:00:00 >=20 > Then, if we run: > select ('2007-03-01 12:00:00'::timestamp + '1 month'::interval) - > '2007-03-01 12:00:00'::timestamp; > we get: 31 days >=20 > But if we run: > select ('2007-02-01 12:00:00'::timestamp + '1 month'::interval) - > '2007-02-01 12:00:00'::timestamp; > we get: 28 days >=20 > So, I'm not sure how many days a month has. >=20 > But your point is valid that given no date to compare to, an interval > of 1 month gets translated to 30 days. I can also see a lot of people > showing up doing fancy interval math THEN wondering why it changes > when you put a timestamp in the middle of it. >=20 Thanx for this well written explanation! =2D-=20 Achilleas Mantzios