8000 Reject out-of-range dates in to_date(). · danielcode/postgres@0471b01 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0471b01

Browse files
committed
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
1 parent 7938d84 commit 0471b01

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/backend/utils/adt/formatting.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,6 +3322,12 @@ to_date(PG_FUNCTION_ARGS)
33223322

33233323
do_to_timestamp(date_txt, fmt, &tm, &fsec);
33243324

3325+
if (!IS_VALID_JULIAN(tm.tm_year, tm.tm_mon, tm.tm_mday))
3326+
ereport(ERROR,
3327+
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3328+
errmsg("date out of range: \"%s\"",
3329+
text_to_cstring(date_txt))));
3330+
33253331
result = date2j(tm.tm_year, tm.tm_mon, tm.tm_mday) - POSTGRES_EPOCH_JDATE;
33263332

33273333
PG_RETURN_DATEADT(result);

0 commit comments

Comments
 (0)
0