> As you see in one of the examples I posted, it does not preserve years and
> months. What exactly does that mean anyway? Simple subtraction also
> preserves years and months, as I see it.
OK, so there is a documentation problem, since the functions do exactly
what they claim!
What do you mean by "it does not preserve years and months"? I look at
the same example, and run the same example here, and it does exactly
what I would expect, in the way I described it in the docs ;)
> > Would we like some additional clarification in the docs perhaps? Seems
> > to be preferable to dropping all mention, especially since it is a
> > useful function.
> By all means.
OK, I'll add some info. But assuming that we are just missing a clear
definition of what "preserves years and months" means, here it is:
Typical date/time arithmetic resolves to an absolute time or interval.
In those cases, *qualitative* quantities such as years and months are
resolved to a specific absolute interval at the time of calculation.
The age() functions *preserve* the qualitative fields year and month. So
you see the difference in results:
lockhart=# select age('today', '1957-06-13');
-------------------------
43 years 9 mons 28 days
lockhart=# select timestamp 'today' - timestamp '1957-06-13';
------------
16008 days
In the case for the DATE type, the result is an integer value (not an
interval) which I believe was done intentionally but I'm not recalling
exactly why; I can research it if necessary:
lockhart=# select date 'today' - date '1957-06-13';
----------
16008
returns the number of days (which is also an absolute, quantitative
time).
- Thomas
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/users-lounge/docs/faq.html