public inbox for [email protected]
help / color / mirror / Atom feedFrom: Alvaro Herrera <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Re: BUG #7722: extract(epoch from age(...)) appears to be broken
Date: Mon, 3 Dec 2012 03:05:57 -0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgsql-bugs>
[email protected] wrote:
> The following bug has been logged on the website:
>
> Bug reference: 7722
> Logged by: Artem Anisimov
> Email address: [email protected]
> 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
I think if you want a precise computation you should just subtract the two
dates and then extract epoch from the result.
alvherre=# select extract(epoch from timestamp '2012-11-22 16:41:31' - '2012-10-23 15:56:10');
date_part
-----------
2594721
(1 fila)
alvherre=# select extract(epoch from timestamp '2012-11-23 16:41:31' - '2012-10-23 15:56:10');
date_part
-----------
2681121
(1 fila)
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
view thread (9+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: BUG #7722: extract(epoch from age(...)) appears to be broken
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox