From: Tom Lane <tgl@sss.pgh.pa.us>
To: Haribabu Kommi <kommi.haribabu@gmail.com>
Cc: John Pruitt <jpruitt@doozer.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #13670: DST discrepancy between age() and subtraction for timestamptz arguments
Date: Mon, 12 Oct 2015 23:49:46 -0400
Message-ID: <6098.1444708186@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJrrPGdTdYuVthRFqRY3R+yWVg5twgrCyhokGQbGkJs1t8NM2g@mail.gmail.com>
References: <20151008223405.1223.38427@wrigleys.postgresql.org>
<CAJrrPGfE1tgnQBqhqBKNwbJ+PqXyooAvHFFQBx2PobumtCMR9Q@mail.gmail.com>
<CACune3x8WM39wXXSGaWRuayKhob+8c3Cpp_rnFL7vPxyoXK7Ng@mail.gmail.com>
<CAJrrPGfjF6-yK8F++fauocH2mahwH6v4GCCxwQr-0gt0ECtKZQ@mail.gmail.com>
<CACune3za1xvptswi7QxnFNAZaBVgVD6Ldf7iGMe8dDfjy3vjCw@mail.gmail.com>
<CAJrrPGdTdYuVthRFqRY3R+yWVg5twgrCyhokGQbGkJs1t8NM2g@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Haribabu Kommi <kommi.haribabu@gmail.com> writes:
> On Tue, Oct 13, 2015 at 1:50 AM, John Pruitt <jpruitt@doozer.com> wrote:
>> Okay, I'll acknowledge that the issue has been discussed before, however I
>> fail to see how the issue can be considered resolved. The function takes
>> time zone aware arguments, ignores that input, and returns plainly incorrect
>> answers - the very definition of a bug.
> I also feel like that it is a bug. Here I attached a patch that
> corrects the problem.
I think you both are fundamentally missing the point.
The age() function exists to provide a "symbolic" difference between two
timestamps. In its intended use-case, the difference between midnight
on March 1 2015 and midnight on April 1 2015 is one month. Not one month
plus or minus an hour.
If you want the other behavior, why aren't you using plain timestamp
subtraction?
regression=# select age('1 april 2015'::timestamptz, '1 march 2015'::timestamptz);
age
-------
1 mon
(1 row)
regression=# select '1 april 2015'::timestamptz - '1 march 2015'::timestamptz;
?column?
------------------
30 days 23:00:00
(1 row)
(This is based on US DST rules, you might get different results in other
timezones.)
Even discounting any thought of backwards compatibility, it does not seem
to me that erasing the distinction between these behaviors is a good
thing. People might legitimately want either one.
Another point worth considering is this:
regression=# select '1 march 2015'::timestamptz + age('1 april 2015'::timestamptz, '1 march 2015'::timestamptz);
?column?
------------------------
2015-04-01 00:00:00-04
(1 row)
While I'm not sure that "X + age(Y, X) = Y" holds universally, it does
hold in this example, and the proposed patch would break that.
Having said that, I notice that the seemingly even more obvious
identity "X + (Y - X) = Y" doesn't work in this case. Maybe we should do
something about that, or maybe not. My point is mainly that there are
a *lot* of moving parts in this area, as well as a considerable amount
of backwards-compatibility history that we must not take lightly. It is
well to remember also that civil time and DST laws were written by
politicians who have never heard of mathematical consistency.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, kommi.haribabu@gmail.com, jpruitt@doozer.com
Subject: Re: BUG #13670: DST discrepancy between age() and subtraction for timestamptz arguments
In-Reply-To: <6098.1444708186@sss.pgh.pa.us>
References: <20151008223405.1223.38427@wrigleys.postgresql.org> <CAJrrPGfE1tgnQBqhqBKNwbJ+PqXyooAvHFFQBx2PobumtCMR9Q@mail.gmail.com> <CACune3x8WM39wXXSGaWRuayKhob+8c3Cpp_rnFL7vPxyoXK7Ng@mail.gmail.com> <CAJrrPGfjF6-yK8F++fauocH2mahwH6v4GCCxwQr-0gt0ECtKZQ@mail.gmail.com> <CACune3za1xvptswi7QxnFNAZaBVgVD6Ldf7iGMe8dDfjy3vjCw@mail.gmail.com> <CAJrrPGdTdYuVthRFqRY3R+yWVg5twgrCyhokGQbGkJs1t8NM2g@mail.gmail.com> <6098.1444708186@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox