File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -5308,10 +5308,16 @@ interval_part_common(PG_FUNCTION_ARGS, bool retnumeric)
5308
5308
int64 secs_from_day_month ;
5309
5309
int64 val ;
5310
5310
5311
- /* this always fits into int64 */
5312
- secs_from_day_month = ((int64 ) DAYS_PER_YEAR * (interval -> month / MONTHS_PER_YEAR ) +
5313
- (int64 ) DAYS_PER_MONTH * (interval -> month % MONTHS_PER_YEAR ) +
5314
- interval -> day ) * SECS_PER_DAY ;
5311
+ /*
5312
+ * To do this calculation in integer arithmetic even though
5313
+ * DAYS_PER_YEAR is fractional, multiply everything by 4 and then
5314
+ * divide by 4 again at the end. This relies on DAYS_PER_YEAR
5315
+ * being a multiple of 0.25 and on SECS_PER_DAY being a multiple
5316
+ * of 4.
5317
+ */
5318
+ secs_from_day_month = ((int64 ) (4 * DAYS_PER_YEAR ) * (interval -> month / MONTHS_PER_YEAR ) +
5319
+ (int64 ) (4 * DAYS_PER_MONTH ) * (interval -> month % MONTHS_PER_YEAR ) +
5320
+ (int64 ) 4 * interval -> day ) * (SECS_PER_DAY / 4 );
5315
5321
5316
5322
/*---
5317
5323
* result = secs_from_day_month + interval->time / 1'000'000
Original file line number Diff line number Diff line change @@ -1655,11 +1655,11 @@ SELECT f1,
1655
1655
@ 1 min | 0 | 0.000 | 0.000000 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 60.000000
1656
1656
@ 5 hours | 0 | 0.000 | 0.000000 | 0 | 5 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 18000.000000
1657
1657
@ 10 days | 0 | 0.000 | 0.000000 | 0 | 0 | 10 | 0 | 1 | 0 | 0 | 0 | 0 | 864000.000000
1658
- @ 34 years | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 1 | 34 | 3 | 0 | 0 | 1072224000 .000000
1658
+ @ 34 years | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 1 | 34 | 3 | 0 | 0 | 1072958400 .000000
1659
1659
@ 3 mons | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 3 | 2 | 0 | 0 | 0 | 0 | 7776000.000000
1660
1660
@ 14 secs ago | -14000000 | -14000.000 | -14.000000 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | -14.000000
1661
1661
@ 1 day 2 hours 3 mins 4 secs | 4000000 | 4000.000 | 4.000000 | 3 | 2 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 93784.000000
1662
- @ 6 years | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 1 | 6 | 0 | 0 | 0 | 189216000 .000000
1662
+ @ 6 years | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 1 | 6 | 0 | 0 | 0 | 189345600 .000000
1663
1663
@ 5 mons | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 5 | 2 | 0 | 0 | 0 | 0 | 12960000.000000
1664
1664
@ 5 mons 12 hours | 0 | 0.000 | 0.000000 | 0 | 12 | 0 | 5 | 2 | 0 | 0 | 0 | 0 | 13003200.000000
1665
1665
(10 rows)
You can’t perform that action at this time.
0 commit comments