Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tfi4L-0008LG-TD for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Dec 2012 02:17:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tfi4K-0001sC-RU for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Dec 2012 02:17:08 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tfi4J-0001rW-UO for pgsql-bugs@postgresql.org; Tue, 04 Dec 2012 02:17:08 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tfi4H-0004sD-L3 for pgsql-bugs@postgresql.org; Tue, 04 Dec 2012 02:17:06 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1Tfi4C-000710-2m; Mon, 03 Dec 2012 21:17:00 -0500 Date: Mon, 3 Dec 2012 21:17:00 -0500 From: Bruce Momjian To: Alvaro Herrera Cc: aanisimov@inbox.ru, pgsql-bugs@postgresql.org Subject: Re: BUG #7722: extract(epoch from age(...)) appears to be broken Message-ID: <20121204021700.GC7675@momjian.us> References: <20121203060556.GA4601@alvh.no-ip.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20121203060556.GA4601@alvh.no-ip.org> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) 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 On Mon, Dec 3, 2012 at 03:05:57AM -0300, Alvaro Herrera wrote: > aanisimov@inbox.ru wrote: > > The following bug has been logged on the website: > > > > Bug reference: 7722 > > Logged by: Artem Anisimov > > Email address: aanisimov@inbox.ru > > PostgreSQL version: 9.2.1 > > Operating system: Slackware Linux 14.0/amd64 > > Description: > > > > The following to queries give the same result (first arguments to age() > > differ in the day number only, second arguments are identical): > > > > select extract(epoch from age('2012-11-23 16:41:31', '2012-10-23 > > 15:56:10')); > > > > and > > > > select extract(epoch from age('2012-11-22 16:41:31', '2012-10-23 > > 15:56:10')); > > alvherre=# select age('2012-11-22 16:41:31', '2012-10-23 15:56:10'); > age > ------------------ > 30 days 00:45:21 > (1 fila) > > alvherre=# select age('2012-11-23 16:41:31', '2012-10-23 15:56:10'); > age > ---------------- > 1 mon 00:45:21 > (1 fila) > > The problem is that age() returns 30 days in one case, and "one month" in the > other; extract() then considers the month as equivalent to 30 days. This is > documented as such, see [1]. > > [1] http://www.postgresql.org/docs/current/static/functions-datetime.html 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. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs