Re: BUG #3431: age() gets the days wrong

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pelle Johansson <pelle(at)morth(dot)org>
Cc: pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #3431: age() gets the days wrong
Date: 2007-07-08 21:56:26
Message-ID: 5675.1183931786@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Pelle Johansson <pelle(at)morth(dot)org> writes:
> If you were to use the result for subtracting from the first value,
> instead of adding to the second, the conditions are reversed. It's
> not really as obvious as I first thought whether there's 2 months and
> 29 days or 2 months and 30 days between 2006-11-02 and 2007-02-01...

Hmm, that's a really good point; perhaps the original author was
thinking of it in those terms, in which case using the first month of
the interval is indeed sane. (Almost: I believe that the loop can
iterate more than once, and then you need to look to the second month
etc. The code's not doing that, so there's still a corner-case bug,
plus the fsec issue.)

Other than that corner case, it seems the behavior we currently have is
if x > y, age() produces a positive interval such that
x - age(x, y) = y
if x < y, age() produces a negative interval such that
y + age(x, y) = x

Are we satisfied with just documenting that, or do we want to change it,
and if so to what?

As the code currently stands, we have the symmetry property
age(x,y) = - age(y,x)
for all x,y. I don't think we can preserve that if we try to simplify
the relationship to interval addition/subtraction.

Comments?

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2007-07-09 14:39:47 numeric stddev_pop and var_pop are wrong
Previous Message Pelle Johansson 2007-07-08 20:58:18 Re: BUG #3431: age() gets the days wrong

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-07-08 22:27:49 Re: pgstat_drop_relation bugfix
Previous Message Stephen Frost 2007-07-08 21:36:24 Re: Should we bump libpq major version for 8.3?

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2007-07-08 22:27:49 Re: pgstat_drop_relation bugfix
Previous Message Pelle Johansson 2007-07-08 20:58:18 Re: BUG #3431: age() gets the days wrong