Skip site navigation (1) Skip section navigation (2)

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

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org, "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 08:41:00
Message-ID: 200805131141.01422.achill@matrix.gatewaynet.com (view raw or flat)
Thread:
Lists: pgsql-admin
Στις Tuesday 13 May 2008 11:22:28 ο/η Scott Marlowe έγραψε:
> On Tue, May 13, 2008 at 12:56 AM, Achilleas Mantzios
> <achill(at)matrix(dot)gatewaynet(dot)com> wrote:
> >  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.
> 
> True.  But that's only because it doesn't have a date to work against.
>  If you run:
> 
> select '2007-02-01 12:00:00'::timestamp + '1 month'::interval;
> you get: 2007-03-01 12:00:00
> 
> If you run:
> select '2007-03-01 12:00:00'::timestamp + '1 month'::interval;
> you get:  2007-04-01 12:00:00
> 
> 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
> 
> 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
> 
> So, I'm not sure how many days a month has.
> 
> 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.
> 

Thanx for this well written explanation!

-- 
Achilleas Mantzios

In response to

pgsql-admin by date

Next:From: Shane AmblerDate: 2008-05-13 08:42:41
Subject: Re: how to get a number of seconds in some interval ?
Previous:From: Scott MarloweDate: 2008-05-13 08:22:28
Subject: Re: how to get a number of seconds in some interval ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group