Re: Re: Data type confusion

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Re: Data type confusion
Дата
Msg-id 13602.997062611@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Re: Data type confusion  (Peter Eisentraut <peter_e@gmx.net>)
Ответы Re: Re: Data type confusion
Список pgsql-sql
Peter Eisentraut <peter_e@gmx.net> writes:
> but

> '2001-08-06 03:03:03' - '2000-08-06 03:03:00' = '365 days 3 seconds'

> '2000-08-06 03:03:03' - '1999-08-06 03:03:00' = '366 days 3 seconds'

What I said was that timestamp plus or minus interval is well-defined
(when "interval" is a multi-part symbolic interval).  It's quite obvious
that timestamp minus timestamp yielding interval is not uniquely
defined: in the above examples one could express the result either as
you show or as '1 year 3 seconds', which I would argue is preferable.

For a 3-part (month/day/second) interval, I think the preferable rule
for timestamp subtraction is to use the largest symbolic component
possible, ie, use the largest number of months/years you can, then
use the largest number of days fitting in the remainder, then express
what's left as seconds.  This is an arbitrary choice among the many
possible 3-part representations of a given interval, but it seems like
the most natural one for many applications.

> a) A value such as '1 year 3 seconds' varies depending on context, which
> is not how our system is intended to work, or

Isn't it?  The relationship between years, days, and seconds is
*inherently* context dependent in the common calendar.  It might not be
too sensible, but sensibleness has never held sway in calendars, at
least not since the Romans.

I think that the actually useful operations for symbolic intervals
have to do with adding them to (or subtracting them from) timestamps.
For example, I know exactly what I think should happen when I write
now() + '1 day'::interval, and that two days out of the year this
should yield a different result from now() + '24 hours'::interval.
Whatever else we do with intervals has to mesh with that as best
we can make it happen.

I'm not sure your notion of fractional months really holds water,
at least not for this particular operation.  When is 25 Feb 2000
plus 0.95 month?  Is the 0.95 measured with respect to the length
of February, or of March?  Does it matter that 2000 is a leap year?
There may be some other operations that have sensible interpretations
for such a datatype, however.
        regards, tom lane


В списке pgsql-sql по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: Re: Data type confusion
Следующее
От: "Josh Berkus"
Дата:
Сообщение: Re: Re: Data type confusion