BUG #17305: to_timestamp accept dates rejected by timestamptz cast

Started by PG Bug reporting formover 4 years ago3 messagesbugs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 17305
Logged by: Chinh Nguyen
Email address: nguyenkhacchinh@hotmail.com
PostgreSQL version: 10.19
Operating system: Linux
Description:

I don't know if this is a bug or just an unusual behavior. I had assumed,
per the documentation, that function to_timestamp() is the same as
timestamptz but with control for different formats.

The following dates are all rejected by timestamptz (e.g., select
'0000-01-01T00:00:01Z'::timestamptz):
0000-01-01T00:00:01Z, 0000-02-29T00:00:01Z, 0000-02-30T00:00:01Z,
0000-02-31T00:00:01Z

But they are accepted by to_timestamp (e.g., select to_timestamp('0000-01-01
00:00:00+00','YYYY-MM-DDThh24:mi:ssZ')). The results from to_timestamp
are:
0001-01-01 00:00:00+00 BC, 0001-02-29 00:00:00+00 BC, 0001-03-01 00:00:00+00
BC, 0001-03-02 00:00:00+00 BC

My version is 10.19 but I also tested against an online test db running
11.10.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: PG Bug reporting form (#1)
Re: BUG #17305: to_timestamp accept dates rejected by timestamptz cast

PG Bug reporting form <noreply@postgresql.org> writes:

I don't know if this is a bug or just an unusual behavior. I had assumed,
per the documentation, that function to_timestamp() is the same as
timestamptz but with control for different formats.

It is not, and I don't see the documentation claiming that it is.

regards, tom lane

#3Chinh Nguyen
nguyenkhacchinh@hotmail.com
In reply to: Tom Lane (#2)
Re: BUG #17305: to_timestamp accept dates rejected by timestamptz cast

I am simply going by this tip in the documentation:

"to_timestamp and to_date exist to handle input formats that cannot be converted by simple casting. For most standard date/time formats, simply casting the source string to the required data type works, and is much easier. Similarly, to_number is unnecessary for standard numeric representations."

It's interesting that 0000-02-31 is acceptable for one but not the other. But given the unlikelihood of seeing this date in data that I process, this behaviour is simply a curiosity.

Regards.
________________________________
From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: December 2, 2021 1:54 PM
To: nguyenkhacchinh@hotmail.com <nguyenkhacchinh@hotmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #17305: to_timestamp accept dates rejected by timestamptz cast

PG Bug reporting form <noreply@postgresql.org> writes:

I don't know if this is a bug or just an unusual behavior. I had assumed,
per the documentation, that function to_timestamp() is the same as
timestamptz but with control for different formats.

It is not, and I don't see the documentation claiming that it is.

regards, tom lane