pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <scott.marlowe@gmail.com>
To: Achilleas Mantzios <achill@matrix.gatewaynet.com>
Cc: pgsql-admin@postgresql.org, "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: Julius Tuskenis <julius@nsoft.lt>
Subject: Re: how to get a number of seconds in some interval ?
Date: Tue, 13 May 2008 02:22:28 -0600
Message-ID: <dcc563d10805130122s7ef074bfra86ee43978c5c65f@mail.gmail.com> (raw)
In-Reply-To: <200805130956.51872.achill@matrix.gatewaynet.com>
References: <482849B0.6050103@nsoft.lt>
	<200805121801.35101.achill@matrix.gatewaynet.com>
	<20080.1210604951@sss.pgh.pa.us>
	<200805130956.51872.achill@matrix.gatewaynet.com>

On Tue, May 13, 2008 at 12:56 AM, Achilleas Mantzios
<achill@matrix.gatewaynet.com> wrote:
> Óôéò Monday 12 May 2008 18:09:11 ï/ç Tom Lane Ýãñáøå:
>> Achilleas Mantzios <achill@matrix.gatewaynet.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.


view thread (11+ messages)  latest in thread

Message-ID: <dcc563d10805130122s7ef074bfra86ee43978c5c65f@mail.gmail.com>
Permalink:  ../dcc563d10805130122s7ef074bfra86ee43978c5c65f@mail.gmail.com/
Also on:    postgresql.org/message-id/dcc563d10805130122s7ef074bfra86ee43978c5c65f@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: scott.marlowe@gmail.com, achill@matrix.gatewaynet.com, tgl@sss.pgh.pa.us, julius@nsoft.lt
  Subject: Re: how to get a number of seconds in some interval ?
  In-Reply-To: <dcc563d10805130122s7ef074bfra86ee43978c5c65f@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox