Commit d163fdb
committed
Fix mis-rounding and overflow hazards in date_bin().
In the case where the target timestamp is before the origin timestamp
and their difference is already an exact multiple of the stride, the
code incorrectly subtracted the stride anyway.
Also detect several integer-overflow cases that previously produced
bogus results. (The submitted patch tried to avoid overflow, but
I'm not convinced it's right, and problematic cases are so far out of
the plausibly-useful range that they don't seem worth sweating over.
Let's just use overflow-detecting arithmetic and throw errors.)
timestamp_bin() and timestamptz_bin() are basically identical and
so had identical bugs. Fix both.
Report and patch by Moaaz Assali, adjusted some by me. Back-patch
to v14 where date_bin() was introduced.
Discussion: https://postgr.es/m/CALkF+nvtuas-2kydG-WfofbRSJpyODAJWun==W-yO5j2R4meqA@mail.gmail.com1 parent 53c2a97 commit d163fdb
File tree
5 files changed
+97
-19
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
5 files changed
+97
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4539 | 4539 | | |
4540 | 4540 | | |
4541 | 4541 | | |
4542 | | - | |
4543 | 4542 | | |
| 4543 | + | |
| 4544 | + | |
4544 | 4545 | | |
4545 | 4546 | | |
4546 | 4547 | | |
| |||
4561 | 4562 | | |
4562 | 4563 | | |
4563 | 4564 | | |
4564 | | - | |
| 4565 | + | |
| 4566 | + | |
| 4567 | + | |
| 4568 | + | |
| 4569 | + | |
4565 | 4570 | | |
4566 | 4571 | | |
4567 | 4572 | | |
4568 | 4573 | | |
4569 | 4574 | | |
4570 | 4575 | | |
4571 | | - | |
4572 | | - | |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
| 4579 | + | |
| 4580 | + | |
| 4581 | + | |
| 4582 | + | |
| 4583 | + | |
| 4584 | + | |
4573 | 4585 | | |
4574 | 4586 | | |
4575 | | - | |
4576 | | - | |
| 4587 | + | |
| 4588 | + | |
| 4589 | + | |
4577 | 4590 | | |
4578 | | - | |
4579 | | - | |
4580 | | - | |
4581 | | - | |
| 4591 | + | |
| 4592 | + | |
| 4593 | + | |
| 4594 | + | |
| 4595 | + | |
| 4596 | + | |
| 4597 | + | |
| 4598 | + | |
4582 | 4599 | | |
4583 | 4600 | | |
4584 | 4601 | | |
| |||
4729 | 4746 | | |
4730 | 4747 | | |
4731 | 4748 | | |
| 4749 | + | |
4732 | 4750 | | |
4733 | 4751 | | |
4734 | 4752 | | |
| |||
4749 | 4767 | | |
4750 | 4768 | | |
4751 | 4769 | | |
4752 | | - | |
| 4770 | + | |
| 4771 | + | |
| 4772 | + | |
| 4773 | + | |
| 4774 | + | |
4753 | 4775 | | |
4754 | 4776 | | |
4755 | 4777 | | |
4756 | 4778 | | |
4757 | 4779 | | |
4758 | 4780 | | |
4759 | | - | |
4760 | | - | |
| 4781 | + | |
| 4782 | + | |
| 4783 | + | |
| 4784 | + | |
| 4785 | + | |
| 4786 | + | |
| 4787 | + | |
| 4788 | + | |
| 4789 | + | |
4761 | 4790 | | |
4762 | 4791 | | |
4763 | | - | |
4764 | | - | |
| 4792 | + | |
| 4793 | + | |
| 4794 | + | |
4765 | 4795 | | |
4766 | | - | |
4767 | | - | |
4768 | | - | |
4769 | | - | |
| 4796 | + | |
| 4797 | + | |
| 4798 | + | |
| 4799 | + | |
| 4800 | + | |
| 4801 | + | |
| 4802 | + | |
| 4803 | + | |
4770 | 4804 | | |
4771 | 4805 | | |
4772 | 4806 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
736 | 736 | | |
737 | 737 | | |
738 | 738 | | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
739 | 746 | | |
740 | 747 | | |
741 | 748 | | |
| |||
747 | 754 | | |
748 | 755 | | |
749 | 756 | | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
750 | 764 | | |
751 | 765 | | |
752 | 766 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
780 | 780 | | |
781 | 781 | | |
782 | 782 | | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
783 | 790 | | |
784 | 791 | | |
785 | 792 | | |
| |||
791 | 798 | | |
792 | 799 | | |
793 | 800 | | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
794 | 808 | | |
795 | 809 | | |
796 | 810 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
271 | 274 | | |
272 | 275 | | |
273 | 276 | | |
| |||
278 | 281 | | |
279 | 282 | | |
280 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
281 | 289 | | |
282 | 290 | | |
283 | 291 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
246 | 249 | | |
247 | 250 | | |
248 | 251 | | |
| |||
253 | 256 | | |
254 | 257 | | |
255 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
256 | 264 | | |
257 | 265 | | |
258 | 266 | | |
| |||
0 commit comments