From: Peter Nelson <peter.nelson@code42.com>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: extract('epoch' from age()) returning wrong number of seconds
Date: Wed, 30 Jul 2014 15:33:14 +0000
Message-ID: <29D4F821F6A75941B4FE0C0AAAE0E7809CA1E6D6@ex01.code42.local> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The forth column in this query is returning the wrong value.
The last two columns in this query should return the same value, 5270400 (the number of seconds in 61 days). Using simple subtraction works fine, but using the age() function it returns 5184000 seconds (60 days). This same behavior can be found using other start/end dates and interval lengths, sometimes age() returns too many seconds, sometimes too few. I did not get any failures below 60 days, but I did not do an exhaustive test of all interval values and a range of start/end dates.
> select version();
version
----------------------------------------------------------------------------------------------
PostgreSQL 9.2.6 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.7.2-5) 4.7.2, 64-bit
(1 row)
Time: 41.898 ms
> select extract('epoch' from ('2013-12-31'::date) - ('2013-12-31'::date - '5184000 seconds'::interval)) as right_answer_subtraction_60_days
,extract('epoch' from age (('2013-12-31'::date) , ('2013-12-31'::date - '5184000 seconds'::interval))) as right_answer_age_60_days
,extract('epoch' from ('2013-12-31'::date) - ('2013-12-31'::date - '5270400 seconds'::interval)) as right_answer_subtraction_61_days
,extract('epoch' from age (('2013-12-31'::date) , ('2013-12-31'::date - '5270400 seconds'::interval))) as wrong_answer_age_61_days;
right_answer_subtraction_60_days | right_answer_age_60_days | right_answer_subtraction_61_days | wrong_answer_age_61_days
----------------------------------+--------------------------+----------------------------------+--------------------------
5184000 | 5184000 | 5270400 | 5184000
(1 row)
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: peter.nelson@code42.com
Subject: Re: extract('epoch' from age()) returning wrong number of seconds
In-Reply-To: <29D4F821F6A75941B4FE0C0AAAE0E7809CA1E6D6@ex01.code42.local>
References: <29D4F821F6A75941B4FE0C0AAAE0E7809CA1E6D6@ex01.code42.local>
* 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