Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 0AD0AB5DC1A for ; Sat, 24 Sep 2011 13:40:19 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 36967-06 for ; Sat, 24 Sep 2011 16:40:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from momjian.us (momjian.us [70.90.9.53]) by mail.postgresql.org (Postfix) with ESMTP id 04C81B5DBE1 for ; Sat, 24 Sep 2011 13:40:11 -0300 (ADT) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id p8OGeAj25442; Sat, 24 Sep 2011 12:40:10 -0400 (EDT) From: Bruce Momjian Message-Id: <201109241640.p8OGeAj25442@momjian.us> Subject: Re: BUG #6220: Flagstaff In-Reply-To: <201109231849.p8NIn9LH006193@wwwmaster.postgresql.org> To: Nicolas Beuzeboc Date: Sat, 24 Sep 2011 12:40:10 -0400 (EDT) CC: pgsql-bugs@postgresql.org X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/164 X-Sequence-Number: 31181 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 http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. +