From: Bruce Momjian <bruce@momjian.us>
To: Nicolas Beuzeboc <nicolasbeuzeboc@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6220: Flagstaff
Date: Sat, 24 Sep 2011 12:40:10 -0400 (EDT)
Message-ID: <201109241640.p8OGeAj25442@momjian.us> (raw)
In-Reply-To: <201109231849.p8NIn9LH006193@wwwmaster.postgresql.org>
Nicolas Beuzeboc wrote:
>
> The following bug has been logged online:
>
> Bug reference: 6220
> Logged by: Nicolas Beuzeboc
> Email address: nicolasbeuzeboc@gmail.com
> PostgreSQL version: 8.4.8
> Operating system: Ubuntu Natty
> Description: Flagstaff
> Details:
>
> There is a month difference between the query results
>
> it's not happening if I take the 7.4999.. number and multiply it by interval
> '1 year'
>
> psql (8.4.8)
> Type "help" for help.
>
> postgres=# select now() - interval '7.5 years', now()- interval
> '7.4999999999999999 year', now() - interval '7.49999999999999999 years';
> ?column? | ?column? |
> ?column?
> -------------------------------+-------------------------------+------------
> -------------------
> 2004-03-23 11:44:30.980895-07 | 2004-04-23 11:44:30.980895-07 | 2004-03-23
> 11:44:30.980895-07
> (1 row)
This problem is expected, and is clearer just looking at the intervals:
test=> select interval '7.5 years';
interval
----------------
7 years 6 mons
(1 row)
test=> select interval '7.49999999999999999 years';
interval
----------------
7 years 6 mons
(1 row)
test=> select interval '7.4999999999999999 years';
interval
----------------
7 years 5 mons
(1 row)
Intervals do not have a fixed time frame so we have to store the
interval in three parts:
typedef struct
{
TimeOffset time; /* all time units other than days, months and
* years */
int32 day; /* days, after time for alignment */
int32 month; /* months and years, after time for alignment */
} Interval;
so we can't adjust the day as the month becomes fractional. The example
you supply is basically just rounding from one month down to another.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
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: bruce@momjian.us, nicolasbeuzeboc@gmail.com
Subject: Re: BUG #6220: Flagstaff
In-Reply-To: <201109241640.p8OGeAj25442@momjian.us>
References: <201109231849.p8NIn9LH006193@wwwmaster.postgresql.org> <201109241640.p8OGeAj25442@momjian.us>
* 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