Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f761oZ677011 for ; Sun, 5 Aug 2001 21:50:35 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f761oBY13605; Sun, 5 Aug 2001 21:50:11 -0400 (EDT) To: Peter Eisentraut cc: Allan Engelhardt , Josh Berkus , pgsql-sql@postgresql.org Subject: Re: Re: Data type confusion In-reply-to: References: Comments: In-reply-to Peter Eisentraut message dated "Mon, 06 Aug 2001 03:33:24 +0200" Date: Sun, 05 Aug 2001 21:50:11 -0400 Message-ID: <13602.997062611@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200108/58 X-Sequence-Number: 4279 Peter Eisentraut 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