Re: '1 year' = '360 days' ????

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Doug McNaught <doug(at)mcnaught(dot)org>, Ricardo Perez Lopez <ricpelo(at)hotmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: '1 year' = '360 days' ????
Date: 2004-10-24 02:29:08
Message-ID: 20041024022908.GA14348@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Oct 23, 2004 at 21:38:15 -0400,
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Doug McNaught <doug(at)mcnaught(dot)org> writes:
> > template1=# select '1 year'::interval = '360 days'::interval;
> > ?column?
> > ----------
> > t
> > (1 row)
>
> Yeah, if you look at interval_cmp_internal() it's fairly obvious why.
> I think that this definition is probably bogus, and that only intervals
> that match exactly (equal months parts *and* equal seconds parts) should
> be considered "equal". However the most obvious way to redefine it
> (compare the months, and only if equal compare the seconds) would lead
> to rather nonintuitive behaviors such as "'1 year' > '1000 days'".
> Anybody have any thoughts about a better way to map the multicomponent
> reality into a one-dimensional sorting order?

You could return NULL for cases where the number of months in the
first interval is less than the second, but the number of seconds in
the second interval is greater than the first.
You could even tighten things down more by using that months have to
be at least 28 days, but not more than 31 days (neglecting daylight
savings time).
If you want to be able to use a btree index, you need a total ordering, so
in that case I think you have to have things work pretty much the way they do
now, including the way the equality operator works.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-10-24 03:36:05 Re: '1 year' = '360 days' ????
Previous Message Tom Lane 2004-10-24 01:38:15 Re: '1 year' = '360 days' ????