Probably it should be worth it to implement a sort of age2(timestamp, timestamp) function that returns ages accounting for leap years, months, days and seconds, without changing the actual implementation of age(timestamp, timestamp).
This results also may be of interest:
1)
select age('2007-04-01'::date, '1917-04-01'::date);
age
-----------------------------------
89 years 11 mons 29 days 23:00:00
2)
select age('2007-04-01'::timestamp without time zone, '1917-04-01'::timestamp without time zone);
age
----------
90 years
3)
select age('2007-04-01'::timestamp without time zone, '1917-04-01'::date);
age
----------
90 years
4)
select age('2007-04-01'::date, '1917-04-01'::timestamp without time zone);
age
----------
90 years
I don’t know if the result of query 1) is the desired output of the age(timestamp, timestamp) function.
Casting to timestamp and all combinations of date provides the same result as queries 2), 3) and 4):
5)
select age('2007-04-01'::timestamp, '1917-04-01'::timestamp);
age
----------
90 years
6)
select age('2007-04-01'::date, '1917-04-01'::timestamp);
age
----------
90 years
7)
select age('2007-04-01'::timestamp, '1917-04-01'::date);
age
----------
90 years
Is there a reason for 1) being different in respect of the other queries?
Kind regards,
Pietro Pugni