Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tfy1L-0006q7-CO for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Dec 2012 19:19:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tfy1K-0002G2-Fu for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Dec 2012 19:19:06 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tfy1J-0002Fx-VX for pgsql-bugs@postgresql.org; Tue, 04 Dec 2012 19:19:06 +0000 Received: from mail-ob0-f174.google.com ([209.85.214.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tfy1H-0003dR-6p for pgsql-bugs@postgresql.org; Tue, 04 Dec 2012 19:19:05 +0000 Received: by mail-ob0-f174.google.com with SMTP id ta14so4151586obb.19 for ; Tue, 04 Dec 2012 11:19:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:x-gm-message-state; bh=YDNL0U2tv0pUsFNFZjs721mQ0oIA/EZ/XhHFdcyMpYo=; b=jOK7aYQDAVSQHOp5XrhhBXINPB/INNZKR61/trFoKb7P1Y7HWbqKxcDAO8HPirPW/+ BXTq/V1dSfZq7K+5xW0GILEhseQBWsf5N90XI7bJxcJGwTuDdkPq1sjUpf4FNOUh6xTb eVubUV4VMkJJuFIn5BqiC1Md5SoCqbRjydpYes4ghNbjU4Kro7/B7RwACy9s0y/MC6N8 Tic02+nxsCWchd7E4zSKIKXdkyCcqfCvO+et3bz9ixPd3mvJfITCLei9u9YELJti5dta Pg7iAoC4twhRJ4UAye3tY/kYzJvCxK3/jH439SDji7QAk5yDonuWlOB0A8kM186QYsrg 10Ow== Received: by 10.60.31.241 with SMTP id d17mr12375479oei.107.1354648741832; Tue, 04 Dec 2012 11:19:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.60.51.194 with HTTP; Tue, 4 Dec 2012 11:18:31 -0800 (PST) In-Reply-To: <20121204021700.GC7675@momjian.us> References: <20121203060556.GA4601@alvh.no-ip.org> <20121204021700.GC7675@momjian.us> From: "Francisco Olarte (M)" Date: Tue, 4 Dec 2012 20:18:31 +0100 Message-ID: Subject: Re: BUG #7722: extract(epoch from age(...)) appears to be broken To: Bruce Momjian Cc: Alvaro Herrera , aanisimov@inbox.ru, pgsql-bugs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQk7pp4pDsMp7KojXk/5wC41vL0yMFieRRHwXggFUNk+MtBLHqLZUCdZEh3en4LCBsTg6VE3 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org > Wow, that is a weird case. In the first test, we count the number of > days because it is less than a full month. In the second case, we call > it a full month, but then forget how long it is. Not sure how we could > improve this. I do not think this needs to be improved, the problem is given two dates you can substract them in three different ways, 1.- (year months)+(days)+(hours minutes seconds), which is what age does and is documented as such. folarte=# select age('2013-11-24 16:41:31','2012-10-23 15:56:10'); age ----------------------------- 1 year 1 mon 1 day 00:45:21 (1 row) Which is apropiate for things like 'I'm xxx old' 2.- (days)+(hours-minutes-seconds), which is what substractint dates do ( or seems to do for me, as I've done: select timestamp '2013-11-23 16:41:31' - '2012-10-23 15:56:10'; ?column? ------------------- 396 days 00:45:21 Which I can not find a use for, but there sure are and I'm doomed to find one soon. 3.- Exact duration ( I do this a lot at work as I need to calculate call durations ): folarte=# select extract(epoch from timestamp '2013-11-23 16:41:31') - extract(epoch from timestamp '2012-10-23 15:56:10'); ?column? ---------- 34217121 (1 row) folarte=# select (extract(epoch from timestamp '2013-11-23 16:41:31') - extract(epoch from timestamp '2012-10-23 15:56:10')) * interval '1 second'; ?column? ------------ 9504:45:21 (1 row) The problem I see is intervals are really complicated and difficult to undestand, so it is at most a documentation problem ( people usually understimate the difficulty of working with them, I see this a lot at work ). Francisco Olarte. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs