Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XCXmf-0004oj-D4 for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Jul 2014 17:35:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XCXme-0004j1-On for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Jul 2014 17:35:24 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XCWL8-0001d9-6m for pgsql-bugs@postgresql.org; Wed, 30 Jul 2014 16:02:54 +0000 Received: from exchange.code42.com ([173.160.123.84]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XCWL0-0007UL-Pv for pgsql-bugs@postgresql.org; Wed, 30 Jul 2014 16:02:51 +0000 Received: from ex01.code42.local ([fe80::e433:8d9e:996d:19a0]) by ex01.code42.local ([fe80::e433:8d9e:996d:19a0%13]) with mapi id 14.02.0328.009; Wed, 30 Jul 2014 10:33:14 -0500 From: Peter Nelson To: "pgsql-bugs@postgresql.org" Subject: extract('epoch' from age()) returning wrong number of seconds Thread-Topic: extract('epoch' from age()) returning wrong number of seconds Thread-Index: AQHPrAuTn2wnK9yNT0KTTk2sPhDxww== Date: Wed, 30 Jul 2014 15:33:14 +0000 Message-ID: <29D4F821F6A75941B4FE0C0AAAE0E7809CA1E6D6@ex01.code42.local> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.10.41.35] Content-Type: multipart/alternative; boundary="_000_29D4F821F6A75941B4FE0C0AAAE0E7809CA1E6D6ex01code42local_" MIME-Version: 1.0 X-Pg-Spam-Score: 0.1 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --_000_29D4F821F6A75941B4FE0C0AAAE0E7809CA1E6D6ex01code42local_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable The forth column in this query is returning the wrong value. The last two columns in this query should return the same value, 5270400 (t= he number of seconds in 61 days). Using simple subtraction works fine, but = using the age() function it returns 5184000 seconds (60 days). This same be= havior can be found using other start/end dates and interval lengths, somet= imes age() returns too many seconds, sometimes too few. I did not get any f= ailures 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'::d= ate - '5184000 seconds'::interval)) as right_answer_subtraction_60_days ,extract('epoch' from age (('2013-12-31'::date) , ('2013-12-31'::d= ate - '5184000 seconds'::interval))) as right_answer_age_60_days ,extract('epoch' from ('2013-12-31'::date) - ('2013-12-31'::d= ate - '5270400 seconds'::interval)) as right_answer_subtraction_61_days ,extract('epoch' from age (('2013-12-31'::date) , ('2013-12-31'::d= ate - '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) --_000_29D4F821F6A75941B4FE0C0AAAE0E7809CA1E6D6ex01code42local_ Content-Type: text/html; charset="us-ascii" Content-ID: <3268EEBEE39FE04A8A5D8A3AE3F00A92@code42.com> Content-Transfer-Encoding: quoted-printable
The forth column in this query is returning the wrong value. 

The last two columns in this query should return the same value, 52704= 00 (the number of seconds in 61 days). Using simple subtraction works fine,= but using the age() function it returns 5184000 seconds (60 days). This sa= me behavior can be found using other start/end dates and interval lengths, sometimes age() returns too many sec= onds, sometimes too few. I did not get any failures below 60 days, but I di= d not do an exhaustive test of all interval values and a range of start/end= dates.



 > select version();
                    =                     &nbs= p; version                   &= nbsp;                    =    
---------------------------------------------------------------------------= -------------------
 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'::d= ate) - ('2013-12-31'::date - '5184000 seconds'::interval))  as right_a= nswer_subtraction_60_days
         ,extract('epoch' from age (('2013-12-31':= :date) , ('2013-12-31'::date - '5184000 seconds'::interval))) as right_answ= er_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_answ= er_age_61_days;
 right_answer_subtraction_60_days | right_answer_age_60_days | right_a= nswer_subtraction_61_days | wrong_answer_age_61_days 
----------------------------------+--------------------------+-----= -----------------------------+--------------------------
                     = ;     5184000 |              &= nbsp;   5184000 |              &nbs= p;           5270400 |        =           5184000
(1 row)

--_000_29D4F821F6A75941B4FE0C0AAAE0E7809CA1E6D6ex01code42local_--