Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uyCwB-0057zQ-3E for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Sep 2025 17:24:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uyCw8-00CcOT-Ee for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Sep 2025 17:24:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uyCw8-00CcOL-6O for pgsql-bugs@lists.postgresql.org; Mon, 15 Sep 2025 17:24:21 +0000 Received: from gaoxing.magnetkern.de ([167.235.225.147]) by magus.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1uyCw4-000ywA-3A for pgsql-bugs@lists.postgresql.org; Mon, 15 Sep 2025 17:24:20 +0000 Received: from titanium.fritz.box (p200300c26f10f800264bfefffe54b09c.dip0.t-ipconnect.de [IPv6:2003:c2:6f10:f800:264b:feff:fe54:b09c]) by gaoxing.magnetkern.de (Postfix) with ESMTPSA id 40C6426FBC; Mon, 15 Sep 2025 19:24:13 +0200 (CEST) Date: Mon, 15 Sep 2025 19:24:17 +0200 From: Jan Behrens To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19053: Inconsistent arithmetic regarding TIMESTAMPTZ and INTERVAL Message-Id: <20250915192417.ba5eae9cdd76a1be244bd4fd@magnetkern.de> In-Reply-To: <615313.1757950889@sss.pgh.pa.us> References: <19053-669df0ccf3d14d52@postgresql.org> <615313.1757950889@sss.pgh.pa.us> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; amd64-portbld-freebsd14.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 15 Sep 2025 11:41:29 -0400 Tom Lane wrote: > AFAICS all of these are behaving as-expected. Well, I would say each calculation by itself can be somewhat explained. But it's the overall combination of behavior that seems inconsistent. In particular: TIMESTAMPTZ '2025-10-27' - TIMESTAMPTZ '2025-10-26' This gives INTERVAL '1 day 01:00:00', which makes sense in some way. However, knowing that '24 hours' are not the same as '1 day', I would rather expect either '25 hours' or '1 day'. The following does actually make sense: TIMESTAMPTZ '2025-10-26' + INTERVAL '1 day 01:00:00' But it's the previous substraction that, given how INTERVAL behaves here, does not make sense. > Yeah, it's confusing, > but expecting calendar calculations to have mathematical rigor is > a fool's errand. I don't expect mathematical rigor, but I would like to have consistent semantics of what INTERVAL '1 day' means, and when it is used and when it is returned. > The intent of what's implemented is to produce > useful results for calculations like > > regression=# SELECT TIMESTAMPTZ '2025-03-30' + INTERVAL '1 day'; > ?column? > ------------------------ > 2025-03-31 00:00:00+02 > (1 row) > > despite the intervening DST change. Yes, I agree that the addition behaves correctly. I just wonder if the substraction would need to return either '1 day' or '25 hours'. But not '1 day 01:00:00'. > regards, tom lane Regards, Jan Behrens