Wrong results of function age(timestamp, timestamp)

From: mmerta <michal(dot)merta(at)greycortex(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Wrong results of function age(timestamp, timestamp)
Date: 2016-10-05 14:01:02
Message-ID: 1475676061981-5924559.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello,

I ecountered strange behaviour of function age(timestamp, timestamp).

Let's say we have two timestamps and we want to compute their age() from
fixed timestamp in past:

SELECT pg_catalog.age('2016-04-30 00:00:01'::TIMESTAMP , '2015-01-01
12:00:00'::TIMESTAMP),
pg_catalog.age('2016-04-29 23:59:59'::TIMESTAMP , '2015-01-01
12:00:00'::TIMESTAMP);

age | age
--------------------------------+--------------------------------
1 year 3 mons 28 days 12:00:01 | 1 year 3 mons 28 days 11:59:59

Results are correct.

If we add '1 day'::interval to original timestamps, both results should be 1
day longer.
Howewer first result is exactly 24 hours longer than it should be:

SELECT pg_catalog.age(('2016-04-30 00:00:01'::TIMESTAMP + '1
day'::INTERVAL), '2015-01-01 12:00:00'::TIMESTAMP),
pg_catalog.age(('2016-04-29 23:59:59'::TIMESTAMP + '1
day'::INTERVAL), '2015-01-01 12:00:00'::TIMESTAMP);
age | age
--------------------------------+--------------------------------
1 year 3 mons 30 days 12:00:01 | 1 year 3 mons 29 days 11:59:59

Am I missing something or is it a bug in function age(timestamp, timestamp)?

I tested this on postgres versions 9.4.6 and 9.5.3 on CentOS 7, using
timezone = 'Europe/Prague' in postgresql.conf.

Regards
Michal Merta

--
View this message in context: http://postgresql.nabble.com/Wrong-results-of-function-age-timestamp-timestamp-tp5924559.html
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Vitaly Burovoy 2016-10-05 14:08:55 Re: BUG #14354: Wrong interpretation of JSON 'null'
Previous Message kouber 2016-10-05 10:12:59 BUG #14354: Wrong interpretation of JSON 'null'