Re: age() function documentation

From: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: lockhart(at)fourpalms(dot)org, Hackers List <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: age() function documentation
Date: 2001-04-11 21:26:21
Message-ID: 3AD4CBFD.AD3FD301@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Len Morgan 2001-04-11 22:08:56 Re: RPM upgrade caveats going from a beta version to RC
Previous Message Lamar Owen 2001-04-11 21:01:46 Re: RPM upgrade caveats going from a beta version to RC