to_timestamp function

From: Gustavsson Mikael <mikael(dot)gustavsson(at)smhi(dot)se>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: to_timestamp function
Date: 2019-03-20 16:12:49
Message-ID: 89DE7C43D727C04CA77C8B7AB82533CD022B4935BF@WINVMSERV464.ad.smhi.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

We recently upgraded from PG9.6 to PG11 and I have some questions regarding the function to_timestamp.

We have an application that for some reason unknown to me uses timestamps with hour = 24.
After upgrade we got som problems with this. The solution is to use cast instead of the function but im curious if this is intentional.

Examles:

In PG9.6 this works:

to_timestamp('2019-03-20 24:00','YYYY-MM-DD HH24:MI')

but in PG11 we get:

ERROR: date/time field value out of range.

I assume this have something to do with this row in releasenotes for PG10:

Make to_timestamp()<https://www.postgresql.org/docs/10/functions-formatting.html#FUNCTIONS-FORMATTING-TABLE> and to_date() reject out-of-range input fields (Artur Zakirov)

* For example, previously to_date('2009-06-40','YYYY-MM-DD') was accepted and returned 2009-07-10. It will now generate an error.

But.

This works in both PG9.6 and PG11:

'2019-03-20 24:00'::timestamp with time zone

and this generates an error in both PG9.6 and PG11:

'2009-06-40'::timestamp with time zone

So my question is, is it intentional that to_timestamp is stricter than cast to timestamp?

kr

Mikael Gustavsson
SMHI / Swedish Meteorological and Hydrological Institute

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-03-20 16:33:20 Re: to_timestamp function
Previous Message Ephebopus 2019-03-20 14:55:52 Windows Server 2019 support state / plans