File tree 5 files changed +30
-1
lines changed
5 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -2713,7 +2713,10 @@ timestamp_mi(PG_FUNCTION_ARGS)
2713
2713
(errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2714
2714
errmsg ("cannot subtract infinite timestamps" )));
2715
2715
2716
- result -> time = dt1 - dt2 ;
2716
+ if (unlikely (pg_sub_s64_overflow (dt1 , dt2 , & result -> time )))
2717
+ ereport (ERROR ,
2718
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2719
+ errmsg ("interval out of range" )));
2717
2720
2718
2721
result -> month = 0 ;
2719
2722
result -> day = 0 ;
Original file line number Diff line number Diff line change @@ -1207,6 +1207,15 @@ SELECT extract(epoch from '5000-01-01 00:00:00'::timestamp);
1207
1207
95617584000.000000
1208
1208
(1 row)
1209
1209
1210
+ -- test edge-case overflow in timestamp subtraction
1211
+ SELECT timestamp '294276-12-31 23:59:59' - timestamp '1999-12-23 19:59:04.224193' AS ok;
1212
+ ok
1213
+ -----------------------------------------
1214
+ @ 106751991 days 4 hours 54.775807 secs
1215
+ (1 row)
1216
+
1217
+ SELECT timestamp '294276-12-31 23:59:59' - timestamp '1999-12-23 19:59:04.224192' AS overflows;
1218
+ ERROR: interval out of range
1210
1219
-- TO_CHAR()
1211
1220
SELECT to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon')
1212
1221
FROM TIMESTAMP_TBL;
Original file line number Diff line number Diff line change @@ -1331,6 +1331,15 @@ SELECT extract(epoch from '5000-01-01 00:00:00+00'::timestamptz);
1331
1331
95617584000.000000
1332
1332
(1 row)
1333
1333
1334
+ -- test edge-case overflow in timestamp subtraction
1335
+ SELECT timestamptz '294276-12-31 23:59:59 UTC' - timestamptz '1999-12-23 19:59:04.224193 UTC' AS ok;
1336
+ ok
1337
+ -----------------------------------------
1338
+ @ 106751991 days 4 hours 54.775807 secs
1339
+ (1 row)
1340
+
1341
+ SELECT timestamptz '294276-12-31 23:59:59 UTC' - timestamptz '1999-12-23 19:59:04.224192 UTC' AS overflows;
1342
+ ERROR: interval out of range
1334
1343
-- TO_CHAR()
1335
1344
SELECT to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon')
1336
1345
FROM TIMESTAMPTZ_TBL;
Original file line number Diff line number Diff line change @@ -326,6 +326,10 @@ SELECT extract(epoch from '294270-01-01 00:00:00'::timestamp);
326
326
-- another internal overflow test case
327
327
SELECT extract(epoch from ' 5000-01-01 00:00:00' ::timestamp );
328
328
329
+ -- test edge-case overflow in timestamp subtraction
330
+ SELECT timestamp ' 294276-12-31 23:59:59' - timestamp ' 1999-12-23 19:59:04.224193' AS ok;
331
+ SELECT timestamp ' 294276-12-31 23:59:59' - timestamp ' 1999-12-23 19:59:04.224192' AS overflows;
332
+
329
333
-- TO_CHAR()
330
334
SELECT to_char(d1, ' DAY Day day DY Dy dy MONTH Month month RM MON Mon mon' )
331
335
FROM TIMESTAMP_TBL;
Original file line number Diff line number Diff line change @@ -306,6 +306,10 @@ SELECT extract(epoch from '294270-01-01 00:00:00+00'::timestamptz);
306
306
-- another internal overflow test case
307
307
SELECT extract(epoch from ' 5000-01-01 00:00:00+00' ::timestamptz );
308
308
309
+ -- test edge-case overflow in timestamp subtraction
310
+ SELECT timestamptz ' 294276-12-31 23:59:59 UTC' - timestamptz ' 1999-12-23 19:59:04.224193 UTC' AS ok;
311
+ SELECT timestamptz ' 294276-12-31 23:59:59 UTC' - timestamptz ' 1999-12-23 19:59:04.224192 UTC' AS overflows;
312
+
309
313
-- TO_CHAR()
310
314
SELECT to_char(d1, ' DAY Day day DY Dy dy MONTH Month month RM MON Mon mon' )
311
315
FROM TIMESTAMPTZ_TBL;
You can’t perform that action at this time.
0 commit comments