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 DC64F9DC9A4 for ; Wed, 1 Mar 2006 17:05:07 -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 92659-06 for ; Wed, 1 Mar 2006 17:05:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.markdilger.com (or-65-40-225-74.sta.sprint-hsd.net [65.40.225.74]) by postgresql.org (Postfix) with ESMTP id 649A99DCB80 for ; Wed, 1 Mar 2006 17:05:05 -0400 (AST) Received: from [192.168.2.6] ([192.168.2.6]) (TLS: TLSv1/SSLv3,256bits,AES256-SHA) by mail.markdilger.com with esmtp; Wed, 01 Mar 2006 13:09:56 -0800 id 00020D63.44060DA4.00004099 Message-ID: <44060C42.50905@markdilger.com> Date: Wed, 01 Mar 2006 13:04:02 -0800 From: Mark Dilger User-Agent: Mozilla Thunderbird 1.0 (X11/20050130) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane CC: Bruce Momjian , pgsql-hackers@postgresql.org Subject: Re: [SQL] Interval subtracting References: <200603012013.k21KDFM21139@candle.pha.pa.us> <14834.1141244891@sss.pgh.pa.us> <44060682.9020505@markdilger.com> <15150.1141246521@sss.pgh.pa.us> In-Reply-To: <15150.1141246521@sss.pgh.pa.us> X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200603/62 X-Sequence-Number: 80460 Tom Lane wrote: > Mark Dilger writes: > >>Tom Lane wrote: >> >>>I guess I would expect a good result to satisfy one of these three >>>cases: >>> * month > 0 and 0 <= day < 30 >>> * month < 0 and -30 < day <= 0 >>> * month = 0 and -30 < day < 30 >>>If you believe that then "1 month -95 days" should justify to >>>"-2 months -5 days". > > >>How would you expect justify_hours to behave? I extrapolate from your rules >>above that: > > >> * month > 0 and 0 <= day < 30 and 0 <= hours < 24 >> * month < 0 and -30 < day <= 0 and -24 < hours <= 0 >> * month = 0 and -30 < day <= 0 and -24 < hours <= 0 >> * month = 0 and 0 <= day < 30 and 0 <= hours < 24 > > > Hmmm ... I think it would be better if the two functions were > independent, if possible. Your spec above implies that justify_hours > implicitly does justify_days as well, which seems a bit restrictive. > > Furthermore, justify_hours should only assume that 1 day == 24 hours, > which while broken by DST is still a lot solider assumption than > justify_days' 1 month == 30 days. I can well believe that a lot of > people only want to make the first assumption. > > So I'm inclined to think that justify_hours is responsible for reducing > the seconds part to less-than-24-hours and pushing any overflow into the > days part (but not touching months), while justify_days is responsible > for reducing the days part to less-than-30-days and pushing any overflow > into the months part (but not touching seconds). If you want both you > apply both functions, probably in that order. (I wonder if there are > any cases where applying justify_days before justify_hours would be > useful. Offhand I can't see one ...) > > regards, tom lane I did not mean to imply that the two functions would be calling each other. Rather, I thought that a user should get sensible results if they called them both together. The current code (without the patch) behaves as follows: select justify_days(justify_hours('1 month 95 days -36:00:00'::interval)); justify_days ------------------------- 4 mons 4 days -12:00:00 which seems inconsistent with the intent of the patch. Shouldn't the patched version return '4 mons 3 days 12:00:00' instead? mark