On Jun 29, 2007, at 13:17 , John D. Burger wrote:
> I can't anything in the docs that explain how intervals print out.
> They seem to show like this:
>
> > select now() - '1990-01-01';
> ?column?
> -------------------------------
> 6388 days 13:06:26.3605600595
Without being anchored with a timestamp, we have no way to know how
long a given month is in the result, so it plays it safe by returning
everything in days.
> or like this:
>
> > select now() - current_date;
> ?column?
> -----------------
> 14:06:46.119788
>
> unless you use age(), which supposedly also returns an interval:
>
> > select age(now(), '1990-01-01');
> age
> -----------------------------------------
> 17 years 5 mons 28 days 14:08:04.524803
>
> Why do the first and third intervals print out differently?
The timestamp[tz]_age functions currently don't use the same
algorithm the timestamp_mi code does. This should probably be
reconciled in the future so results are consistent.
> But age() is documented as simply producing an interval - where is
> the magic that makes the first and third results above look different?
src/backend/utils/adt/timestamp.c
> Ah, wait a minute - does this have to do with the varying number of
> days in different months?
Yes.
Michael Glaesemann
grzm seespotcode net