Re: how to get a number of seconds in some interval ?

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Julius Tuskenis <julius(at)nsoft(dot)lt>
Subject: Re: how to get a number of seconds in some interval ?
Date: 2008-05-13 06:56:50
Message-ID: 200805130956.51872.achill@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Στις Monday 12 May 2008 18:09:11 ο/η Tom Lane έγραψε:
> Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com> writes:
> > Στις Monday 12 May 2008 17:32:39 ο/η Julius Tuskenis έγραψε:
> >> 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' =
> >> 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=30 days, and 1 day = 24 hours) has already been made
in the extract function.

> You can derive a number if you're willing to make arbitrary assumptions
> about the relationships of the different units (as indeed extract(epoch)
> does), but hard-wiring such assumptions into a basic arithmetic operator
> doesn't seem like a good idea to me.
>
> regards, tom lane
>

--
Achilleas Mantzios

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Scott Marlowe 2008-05-13 08:22:28 Re: how to get a number of seconds in some interval ?
Previous Message Julius Tuskenis 2008-05-13 06:20:09 Re: how to get a number of seconds in some interval ?