Re: BUG #7722: extract(epoch from age(...)) appears to be broken

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: aanisimov(at)inbox(dot)ru, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7722: extract(epoch from age(...)) appears to be broken
Date: 2012-12-04 02:17:00
Message-ID: 20121204021700.GC7675@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-docs

On Mon, Dec 3, 2012 at 03:05:57AM -0300, Alvaro Herrera wrote:
> aanisimov(at)inbox(dot)ru wrote:
> > The following bug has been logged on the website:
> >
> > Bug reference: 7722
> > Logged by: Artem Anisimov
> > Email address: aanisimov(at)inbox(dot)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 <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Артем Анисимов 2012-12-04 05:16:14 Re: BUG #7722: extract(epoch from age(...)) appears to be broken
Previous Message Tom Lane 2012-12-03 18:14:48 Re: BUG #7726: Can't paste sqls size>4096 to psql console.

Browse pgsql-docs by date

  From Date Subject
Next Message Артем Анисимов 2012-12-04 05:16:14 Re: BUG #7722: extract(epoch from age(...)) appears to be broken
Previous Message Tom Lane 2012-12-03 16:10:09 Re: [PATCH] Fix return type documentation for path(polygon) function