aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-01-14 15:19:48 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-01-14 15:20:02 -0500
commit0471b013aab87ebfbb767e9456c7b619d5c2b9d3 (patch)
tree0c33d292cc3470de149b0b0e01cd894e3e65a99a /src/backend/utils
parent7938d84a3234594a9183fcdc84c855c4b883c3bb (diff)
downloadpostgresql-0471b013aab87ebfbb767e9456c7b619d5c2b9d3.tar.gz
postgresql-0471b013aab87ebfbb767e9456c7b619d5c2b9d3.zip
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
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/formatting.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index b46cb876150..65bca38b2dd 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -3322,6 +3322,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);