pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peterko <coolman.peto@centrum.cz>
To: Greg Stark <stark@mit.edu>
To: Vik Fearing <vik@2ndquadrant.fr>
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14313: justify interval bug
Date: Mon, 05 Sep 2016 21:12:00 +0200
Message-ID: <20160905211200.C0EA4356@centrum.cz> (raw)
References: <20160905163158.1413.60004@wrigleys.postgresql.org>
	<ec1a37b1-9bbb-d06c-df28-4250917f2447@2ndquadrant.fr>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hi,
my use case is that I need track event every 3 years and 10 months after previous event and keep in touch with object in upper limit for period of 3 years 10 months and 2 weeks.I performed comparison localtimestamp with the previous event date and if the interval was higher than interval of 3 years and 10 months and lower than interval of 3 years 10 months and 2 weeks, the the result is marked as target for next touch.
 
My question is, whether is it safe to subtract two timestamps and then compare interval without justify function with target interval (target interval is 3 years and 10 months, or 5 years and 10 months, or 7 years and 10 months, etc...). Or do I need recalculate the years of target interval to months?
If I subtract two timestamps, is the internally stored correct number of days in interval value?
 
Best regards
 
Peter
______________________________________________________________
> Od: Greg Stark <stark@mit.edu>
> Komu: Vik Fearing <vik@2ndquadrant.fr>
> Datum: 05.09.2016 20:29
> Předmět: Re: BUG #14313: justify interval bug
>
> CC: <pgsql-bugs@postgresql.org>
On Mon, Sep 5, 2016 at 6:59 PM, Vik Fearing <vik@2ndquadrant.fr> wrote:
 > Your timestamp subtraction results in 7305 days.  The justify_interval
 > function, not knowing anything about where those days came from, will
 > use 30 days per month, giving you the result you see.
 
 Part of the story that's not apparent here is that intervals track
 months and days
 separately but don't track years separately. So the justified interval
 internally is actually 243 months, 15 days, and 0 seconds. The "20
 years" is just part of the output format.
 
 The reason years aren't tracked separately is that they're always 12
 months. So if you want an event in your calendar that occurs every
 year on the same date you can add an interval like '12 months' to it
 and it'll always add exactly a year and land on the same date
 regardless of the number of days in the year.
 
 -- 
 greg


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (5+ messages)

Message-ID: <20160905211200.C0EA4356@centrum.cz>
Permalink:  ../20160905211200.C0EA4356@centrum.cz/
Also on:    postgresql.org/message-id/20160905211200.C0EA4356@centrum.cz

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: coolman.peto@centrum.cz, stark@mit.edu, vik@2ndquadrant.fr
  Subject: Re: BUG #14313: justify interval bug
  In-Reply-To: <20160905211200.C0EA4356@centrum.cz>
  References: <20160905163158.1413.60004@wrigleys.postgresql.org> <ec1a37b1-9bbb-d06c-df28-4250917f2447@2ndquadrant.fr> <20160905211200.C0EA4356@centrum.cz>

* 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