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);