From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: c.maurer@gmx.at
Subject: BUG #18313: No error triggered when subtracting an interval from a timestamp
Date: Fri, 26 Jan 2024 13:06:03 +0000
Message-ID: <18313-64d2c8952d81e84b@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 18313
Logged by: Christian Maurer
Email address: c.maurer@gmx.at
PostgreSQL version: 16.1
Operating system: RHEL 9
Description:
Hi
The SQL script below uses an anchor date (2000-01-01) in a table and tries
to subtract an interval (in days) from it.
Considering the timestamp range, the maximum number of days that can be
successfully subtracted should be 2451545. All higher values are then
expected to trigger an exception.
However, when subtracting 2483590, no error is triggered. This is true up to
2539738.
Subtracting 2539739 again shows an error message.
Is this the intended behavior?
Platform: We use PostgreSQL 16.1 (PGDG) under Red Hat Enterprise Linux 9
with standard settings.
Regards,
Christian
create table tbl_timestamp_limit (anchor_date TIMESTAMP(6), offset_value
BIGINT);
insert into tbl_timestamp_limit (anchor_date) values
(to_timestamp('20000101','YYYYMMDD'));
-- the maximum value in days we can subtract from '2000-01-01' without an
error is 2451545
update tbl_timestamp_limit set offset_value=2483589;
-- 2483589 fails as expected
SELECT (anchor_date - INTERVAL '1 day' * (offset_value)) FROM
tbl_timestamp_limit;
-- one day more
update tbl_timestamp_limit set offset_value=2483590;
-- 2483590 surprisingly succeeds, no error is triggered
SELECT (anchor_date - INTERVAL '1 day' * (offset_value)) FROM
tbl_timestamp_limit;
update tbl_timestamp_limit set offset_value=2539738;
-- 2539738 still does not trigger an error
SELECT (anchor_date - INTERVAL '1 day' * (offset_value)) FROM
tbl_timestamp_limit;
update tbl_timestamp_limit set offset_value=2539739;
-- 2539739 fails as expected
SELECT (anchor_date - INTERVAL '1 day' * (offset_value)) FROM
tbl_timestamp_limit;
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: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, c.maurer@gmx.at
Subject: Re: BUG #18313: No error triggered when subtracting an interval from a timestamp
In-Reply-To: <18313-64d2c8952d81e84b@postgresql.org>
* 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