forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit226ec49
committed
Fix division-by-zero error in to_char() with 'EEEE' format.
This fixes a long-standing bug when using to_char() to format anumeric value in scientific notation -- if the value's exponent isless than -NUMERIC_MAX_DISPLAY_SCALE-1 (-1001), it produced adivision-by-zero error.The reason for this error was that get_str_from_var_sci() divides itsinput by 10^exp, which it produced using power_var_int(). However, theunderflow test in power_var_int() causes it to return zero if theresult scale is too small. That's not a problem for power_var_int()'sonly other caller, power_var(), since that limits the rscale to 1000,but in get_str_from_var_sci() the exponent can be much smaller,requiring a much larger rscale. Fix by introducing a new function tocompute 10^exp directly, with no rscale limit. This also allows 10^expto be computed more efficiently, without any numeric multiplication,division or rounding.Discussion:https://postgr.es/m/CAEZATCWhojfH4whaqgUKBe8D5jNHB8ytzemL-PnRx+KCTyMXmg@mail.gmail.com1 parent87bff68 commit226ec49
File tree
3 files changed
+76
-29
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
3 files changed
+76
-29
lines changedLines changed: 37 additions & 29 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
428 | 428 |
| |
429 | 429 |
| |
430 | 430 |
| |
431 |
| - | |
432 |
| - | |
433 |
| - | |
434 |
| - | |
435 |
| - | |
436 |
| - | |
437 |
| - | |
438 |
| - | |
439 |
| - | |
440 |
| - | |
441 | 431 |
| |
442 | 432 |
| |
443 | 433 |
| |
| |||
582 | 572 |
| |
583 | 573 |
| |
584 | 574 |
| |
| 575 | + | |
585 | 576 |
| |
586 | 577 |
| |
587 | 578 |
| |
| |||
7210 | 7201 |
| |
7211 | 7202 |
| |
7212 | 7203 |
| |
7213 |
| - | |
7214 |
| - | |
7215 |
| - | |
| 7204 | + | |
7216 | 7205 |
| |
7217 | 7206 |
| |
7218 | 7207 |
| |
| |||
7249 | 7238 |
| |
7250 | 7239 |
| |
7251 | 7240 |
| |
7252 |
| - | |
7253 |
| - | |
7254 |
| - | |
7255 |
| - | |
| 7241 | + | |
| 7242 | + | |
7256 | 7243 |
| |
7257 |
| - | |
7258 |
| - | |
7259 |
| - | |
7260 |
| - | |
7261 |
| - | |
7262 |
| - | |
7263 |
| - | |
| 7244 | + | |
7264 | 7245 |
| |
7265 |
| - | |
7266 |
| - | |
7267 |
| - | |
| 7246 | + | |
| 7247 | + | |
| 7248 | + | |
7268 | 7249 |
| |
7269 |
| - | |
7270 |
| - | |
| 7250 | + | |
7271 | 7251 |
| |
7272 | 7252 |
| |
7273 | 7253 |
| |
| |||
10519 | 10499 |
| |
10520 | 10500 |
| |
10521 | 10501 |
| |
| 10502 | + | |
| 10503 | + | |
| 10504 | + | |
| 10505 | + | |
| 10506 | + | |
| 10507 | + | |
| 10508 | + | |
| 10509 | + | |
| 10510 | + | |
| 10511 | + | |
| 10512 | + | |
| 10513 | + | |
| 10514 | + | |
| 10515 | + | |
| 10516 | + | |
| 10517 | + | |
| 10518 | + | |
| 10519 | + | |
| 10520 | + | |
| 10521 | + | |
| 10522 | + | |
| 10523 | + | |
| 10524 | + | |
| 10525 | + | |
| 10526 | + | |
| 10527 | + | |
| 10528 | + | |
| 10529 | + | |
10522 | 10530 |
| |
10523 | 10531 |
| |
10524 | 10532 |
| |
|
Lines changed: 32 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1794 | 1794 |
| |
1795 | 1795 |
| |
1796 | 1796 |
| |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
1797 | 1829 |
| |
1798 | 1830 |
| |
1799 | 1831 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
939 | 939 |
| |
940 | 940 |
| |
941 | 941 |
| |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
942 | 949 |
| |
943 | 950 |
| |
944 | 951 |
| |
|
0 commit comments
Comments
(0)