diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-01-14 15:19:48 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-01-14 15:20:15 -0500 |
commit | d4c78c1811d14b14f47f3611bf2c2c1a35817988 (patch) | |
tree | e28386d14ab20c4a62006a6e51a183a5c033e637 | |
parent | dc0c987574d89b4f257218e91adac1537a4c2c3e (diff) | |
download | postgresql-d4c78c1811d14b14f47f3611bf2c2c1a35817988.tar.gz |
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
-rw-r--r-- | src/backend/utils/adt/formatting.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index 1a52429624..d69d27343b 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -3303,6 +3303,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); |