Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 682B29FB34B; Thu, 5 Oct 2006 13:51:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 24987-03; Thu, 5 Oct 2006 13:50:55 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 06A329FB310; Thu, 5 Oct 2006 13:50:54 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k95GosKm021620; Thu, 5 Oct 2006 12:50:54 -0400 (EDT) To: gdavis@refractions.net cc: pgsql-sql@postgresql.org, pgsql-hackers@postgresql.org Subject: timestamp subtraction (was Re: formatting intervals with to_char) In-reply-to: <4522EC42.1080500@refractions.net> References: <4522EC42.1080500@refractions.net> Comments: In-reply-to Graham Davis message dated "Tue, 03 Oct 2006 16:03:30 -0700" Date: Thu, 05 Oct 2006 12:50:54 -0400 Message-ID: <21619.1160067054@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.092 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200610/60 X-Sequence-Number: 26449 Graham Davis writes: > The documentation for to_char states that: > "|to_char(interval)| formats HH and HH12 as hours in a single day, while > HH24 can output hours exceeding a single day, e.g. >24." > However I can not get it to work with time intervals that span more than > 1 day. Well, it does in fact print intervals exceeding 24 hours: regression=# select to_char('48 hours'::interval, 'HH24:MI:SS'); to_char ---------- 48:00:00 (1 row) However, '48 hours' and '2 days' are not the same thing. The problem with the case you give is really that timestamp_mi applies justify_hours to its result --- that is, regression=# select ('2006-09-15 23:59:00'::timestamp - '2006-09-01 09:30:41'::timestamp); ?column? ------------------ 14 days 14:28:19 (1 row) should be reporting '350:28:19' instead. This is a hack that was done to minimize the changes in the regression test expected outputs when we changed type interval from months/seconds to months/days/seconds. But I wonder whether it wasn't a dumb idea. It is certainly inconsistent, as noted in the code comments. I'm tempted to propose that we remove the justify_hours call, and tell anyone who really wants the old results to apply justify_hours() to the subtraction result for themselves. Not sure what the fallout would be, though. regards, tom lane