Re: '1 year' = '360 days' ???? - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: '1 year' = '360 days' ????
Date
Msg-id 20041024022908.GA14348@wolff.to
Whole thread Raw
In response to Re: '1 year' = '360 days' ????  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: '1 year' = '360 days' ????  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Sat, Oct 23, 2004 at 21:38:15 -0400,
  Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Doug McNaught <doug@mcnaught.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.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: '1 year' = '360 days' ????
Next
From: Tom Lane
Date:
Subject: Re: '1 year' = '360 days' ????