From 9aa4caff4f1802ed1b8310973aa032711c7c0366 Mon Sep 17 00:00:00 2001 From: luo_zihao5524 Date: Tue, 2 Aug 2022 11:34:48 +0800 Subject: [PATCH] =?UTF-8?q?to=5Ftimestamp=E6=8A=A5=E9=94=99=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/adt/timestamp.cpp | 6 ++++-- src/test/regress/expected/hw_to_timestamp.out | 3 +++ src/test/regress/sql/hw_to_timestamp.sql | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/common/backend/utils/adt/timestamp.cpp b/src/common/backend/utils/adt/timestamp.cpp index a7149ee38..ebb8c9e4d 100644 --- a/src/common/backend/utils/adt/timestamp.cpp +++ b/src/common/backend/utils/adt/timestamp.cpp @@ -5865,7 +5865,8 @@ Datum float8_timestamptz(PG_FUNCTION_ARGS) /* Out of range? */ if (seconds < (float8) SECS_PER_DAY * (DATETIME_MIN_JULIAN - UNIX_EPOCH_JDATE) || seconds >= (float8) SECS_PER_DAY * (TIMESTAMP_END_JULIAN - UNIX_EPOCH_JDATE)) { - ereport(ERROR, (errmsg("timestamp out of range: \"%g\"", seconds))); + ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range: \"%g\"", seconds))); } /* Convert UNIX epoch to Postgres epoch */ @@ -5876,7 +5877,8 @@ Datum float8_timestamptz(PG_FUNCTION_ARGS) /* Recheck in case roundoff produces something just out of range */ if (!IS_VALID_TIMESTAMP(result)) { - ereport(ERROR, (errmsg("timestamp out of range: \"%g\"", PG_GETARG_FLOAT8(0)))); + ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range: \"%g\"", PG_GETARG_FLOAT8(0)))); } } diff --git a/src/test/regress/expected/hw_to_timestamp.out b/src/test/regress/expected/hw_to_timestamp.out index 4a3d4f25a..f8f9b7602 100644 --- a/src/test/regress/expected/hw_to_timestamp.out +++ b/src/test/regress/expected/hw_to_timestamp.out @@ -1035,3 +1035,6 @@ SELECT to_timestamp('-Infinity'::float); SELECT to_timestamp('NaN'::float); ERROR: timestamp cannot be NaN CONTEXT: referenced column: to_timestamp +SELECT to_timestamp(-999888762478); +ERROR: timestamp out of range: "-9.99889e+11" +CONTEXT: referenced column: to_timestamp diff --git a/src/test/regress/sql/hw_to_timestamp.sql b/src/test/regress/sql/hw_to_timestamp.sql index c4b0d54e8..5b34f398a 100644 --- a/src/test/regress/sql/hw_to_timestamp.sql +++ b/src/test/regress/sql/hw_to_timestamp.sql @@ -269,3 +269,4 @@ end; SELECT to_timestamp(' Infinity'::float); SELECT to_timestamp('-Infinity'::float); SELECT to_timestamp('NaN'::float); +SELECT to_timestamp(-999888762478);