X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 60414D1BACD for ; Sun, 6 Jun 2004 19:40:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31340-08 for ; Sun, 6 Jun 2004 22:40:57 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 34EE1D1BA9E for ; Sun, 6 Jun 2004 19:40:54 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i56MeuWY021475; Sun, 6 Jun 2004 18:40:57 -0400 (EDT) To: Karel Zak Cc: pgsql-sql@postgresql.org Subject: Re: Formatting problems with negative intervals, TO_CHAR In-reply-to: <13d849b7ee63de04179c102cb25159d2@news.teranews.com> References: <13d849b7ee63de04179c102cb25159d2@news.teranews.com> Comments: In-reply-to Jeff Boes message dated "Thu, 03 Jun 2004 20:03:17 +0000" Date: Sun, 06 Jun 2004 18:40:56 -0400 Message-ID: <21474.1086561656@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/46 X-Sequence-Number: 17991 Jeff Boes writes: > This seems ... well, counter-intuitive at least: > (using Pg 7.4.1) > # select to_char('4 minutes'::interval - > '5 minutes 30 seconds'::interval, 'mi:ss'); > to_char > --------- > -1:-3 > (1 row) > Why is the trailing zero lost? Why are there two minus signs? > I would expect '-1:30'. Yeah, me too. The underlying interval value seems right: regression=# select '4 minutes'::interval - '5 minutes 30 seconds'::interval; ?column? ----------- -00:01:30 (1 row) so I think this is a to_char() bug. Possibly it's platform-dependent --- the roundoff behavior for division with a negative input varies across machines. However I do see the bug on HPUX 10.20 with CVS tip. > Likewise, > # select to_char('4 minutes'::interval - > '4 minutes 30 seconds'::interval, 'mi:ss'); > to_char > --------- > 00:-3 > (1 row) regards, tom lane