postgres.git / summary / log / commit / refs
commit 78298daa4e4c890cf397f9aaf4598987bb2f6d5b
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon Jan 14 20:19:48 2013 +0000
First released in: 9.3.0, 8.4.16, 9.0.12, 9.1.8, 9.2.3
Reject out-of-range dates in to_date().
Dates outside the supported range could be entered, but would not print
reasonably, and operations such as conversion to timestamp wouldn't behave
sanely either. Since this has the potential to result in undumpable table
data, it seems worth back-patching.
Hitoshi Harada
src/backend/utils/adt/formatting.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index d86e1140ce7..5b210ebeaeb 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -3074,6 +3074,12 @@ to_date(PG_FUNCTION_ARGS)
do_to_timestamp(date_txt, fmt, &tm, &fsec);
+ if (!IS_VALID_JULIAN(tm.tm_year, tm.tm_mon, tm.tm_mday))
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("date out of range: \"%s\"",
+ text_to_cstring(date_txt))));
+
result = date2j(tm.tm_year, tm.tm_mon, tm.tm_mday) - POSTGRES_EPOCH_JDATE;
PG_RETURN_DATEADT(result);
[parent: ec6de23a0c0d]