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 D5714D1B211 for ; Tue, 20 Jul 2004 05:18:12 -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 53403-06 for ; Tue, 20 Jul 2004 08:18:08 +0000 (GMT) Received: from smtp.ualg.pt (smtp.ualg.pt [193.136.224.8]) by svr1.postgresql.org (Postfix) with ESMTP id E8EC1D1B16A for ; Tue, 20 Jul 2004 05:18:04 -0300 (ADT) Received: from localhost (smtp.ualg.pt [127.0.0.1]) by smtp.ualg.pt (Postfix) with ESMTP id 3E9EF4BE16; Tue, 20 Jul 2004 09:18:04 +0100 (WEST) Received: from smtp.ualg.pt ([127.0.0.1]) by localhost (smtp.ualg.pt [127.0.0.1]) (amavisd-new, port 10024) with SMTP id 17909-10; Tue, 20 Jul 2004 09:17:59 +0100 (WEST) Received: from ualg.pt (corisco.uceh.ualg.pt [10.10.20.126]) by smtp.ualg.pt (Postfix) with ESMTP id DAA424BE21; Tue, 20 Jul 2004 09:17:15 +0100 (WEST) Message-ID: <40FCD50B.40509@ualg.pt> Date: Tue, 20 Jul 2004 09:17:15 +0100 From: Luis Sousa User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413 Debian/1.6-5 X-Accept-Language: en-pt MIME-Version: 1.0 To: "Alexander M. Pravking" Cc: Tom Lane , Theodore Petrosky , pgsql-sql@postgresql.org Subject: Re: Problem in age on a dates interval References: <20040716115215.29699.qmail@web41010.mail.yahoo.com> <20678.1089988447@sss.pgh.pa.us> <40FB8DC2.1080405@ualg.pt> <20040719104646.GH81997@dyatel.antar.bryansk.ru> In-Reply-To: <20040719104646.GH81997@dyatel.antar.bryansk.ru> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new 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: 200407/123 X-Sequence-Number: 18375 Yes, that's a much more clever solution than the one I used. Thanks Best regards, Luis Sousa Alexander M. Pravking wrote: >On Mon, Jul 19, 2004 at 10:00:50AM +0100, Luis Sousa wrote: > > >>I worked around this problem returning the difference between the two >>dates, using extract doy from both. >>Anyway, this will cause a bug on my code when changing the year. Any ideas? >> >> > >Why don't you use the minus operator? > >SELECT '2004-05-14 16:00'::timestamp - '2004-02-18 16:00'::timestamp; > ?column? >---------- > 86 days > >Or, if you need the age just in days: > >SELECT extract(day from '2004-05-14 16:00'::timestamp - '2004-02-18 16:00'::timestamp); > date_part >----------- > 86 > >or > >SELECT '2004-05-14 16:00'::date - '2004-02-18 16:00'::date; > ?column? >---------- > 86 > >Note that '2004-05-14 16:00'::date is actually '2004-05-14 00:00'::date, >so the last two are not always equal. > > > > >>Tom Lane wrote: >> >> >> >>>Theodore Petrosky writes: >>> >>> >>> >>> >>>>wow.... at first I thought I had my head around a leap >>>>year problem so I advanced your query a year.... >>>> >>>> >>>> >>>> >>>I think what's going on here is a difference of interpretation about >>>whether an "M months D days" interval means to add the months first >>>or the days first. For instance >>> >>>2005-02-18 plus 2 months = 2005-04-18, plus 24 days = 2005-05-12 >>> >>>2005-02-18 plus 24 days = 2005-03-14, plus 2 months = 2005-05-14 >>> >>>The timestamp-plus-interval operator is evidently doing addition the >>>first way, but it looks like age() is calculating the difference in a >>>way that implicitly corresponds to the second way. >>> >>>I have some vague recollection that this has come up before, but >>>I don't recall whether we concluded that age() needs to be changed >>>or not. In any case it's not risen to the top of anyone's to-do list, >>>because I see that age() still acts this way in CVS tip. >>> >>> regards, tom lane >>> >>> > > >