X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1CF599DCBD5 for ; Wed, 1 Mar 2006 17:46:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97765-08 for ; Wed, 1 Mar 2006 17:46:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 4E53F9DCC4A for ; Wed, 1 Mar 2006 17:45:57 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k21LjRX11928; Wed, 1 Mar 2006 16:45:27 -0500 (EST) From: Bruce Momjian Message-Id: <200603012145.k21LjRX11928@candle.pha.pa.us> Subject: Re: [SQL] Interval subtracting In-Reply-To: <44061060.8080407@markdilger.com> To: Mark Dilger Date: Wed, 1 Mar 2006 16:45:27 -0500 (EST) CC: Tom Lane , pgsql-hackers@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.413 required=5 tests=[AWL=-0.087, RAZOR2_CHECK=0.5] X-Spam-Score: 0.413 X-Spam-Level: X-Archive-Number: 200603/65 X-Sequence-Number: 80463 Mark Dilger wrote: > Your proposal is that justify_hours borrows 24 hours from the days column in > order to bring the -12 hours up to a positive 12 hours. Should it only do that > if the days column is a positive number? What if it is negative? > > I think we all agree on the following but nobody is explicitly saying so: > > select justify_days(justify_hours('2 days -12:00:00'::interval)) > justify_days > ------------------------- > 1 day 12:00:00 Right. > select justify_days(justify_hours('-2 days -12:00:00'::interval)) > justify_days > ------------------------- > -2 days -12:00:00 Right, unchanged. > Am I correct that the second case should still have negative hours? If so, then > justify_hours(...) needs to examine the sign of the days and months portion of > the interval while performing its work. Yes, it would need to look at both, and this opens a new problem. Imagine this: '1 mons -2 days -12:00:00' Which sign do we head to for this? For justify_hours, if we don't look at the months it remains unchange, but calling justify_days we get: '28 days -12:00:00' which is wrong (negative and positive). Now if we knew justify_days was going to be called we would have had justify_hours return '-3 days 12:00:00' so the final result after calling justify_days would be '27 days 12:00:00'. My head hurts. -- Bruce Momjian http://candle.pha.pa.us SRA OSS, Inc. http://www.sraoss.com + If your life is a hard drive, Christ can be your backup. +