forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit4851940
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 parent554a764 commit4851940
File tree
3 files changed
+78
-29
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
3 files changed
+78
-29
lines changedLines changed: 37 additions & 29 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
381 | 381 |
| |
382 | 382 |
| |
383 | 383 |
| |
384 |
| - | |
385 |
| - | |
386 |
| - | |
387 |
| - | |
388 |
| - | |
389 |
| - | |
390 |
| - | |
391 |
| - | |
392 |
| - | |
393 |
| - | |
394 | 384 |
| |
395 | 385 |
| |
396 | 386 |
| |
| |||
529 | 519 |
| |
530 | 520 |
| |
531 | 521 |
| |
| 522 | + | |
532 | 523 |
| |
533 | 524 |
| |
534 | 525 |
| |
| |||
6015 | 6006 |
| |
6016 | 6007 |
| |
6017 | 6008 |
| |
6018 |
| - | |
6019 |
| - | |
6020 |
| - | |
| 6009 | + | |
6021 | 6010 |
| |
6022 | 6011 |
| |
6023 | 6012 |
| |
| |||
6054 | 6043 |
| |
6055 | 6044 |
| |
6056 | 6045 |
| |
6057 |
| - | |
6058 |
| - | |
6059 |
| - | |
6060 |
| - | |
| 6046 | + | |
| 6047 | + | |
6061 | 6048 |
| |
6062 |
| - | |
6063 |
| - | |
6064 |
| - | |
6065 |
| - | |
6066 |
| - | |
6067 |
| - | |
6068 |
| - | |
| 6049 | + | |
6069 | 6050 |
| |
6070 |
| - | |
6071 |
| - | |
6072 |
| - | |
| 6051 | + | |
| 6052 | + | |
| 6053 | + | |
6073 | 6054 |
| |
6074 |
| - | |
6075 |
| - | |
| 6055 | + | |
6076 | 6056 |
| |
6077 | 6057 |
| |
6078 | 6058 |
| |
| |||
8561 | 8541 |
| |
8562 | 8542 |
| |
8563 | 8543 |
| |
| 8544 | + | |
| 8545 | + | |
| 8546 | + | |
| 8547 | + | |
| 8548 | + | |
| 8549 | + | |
| 8550 | + | |
| 8551 | + | |
| 8552 | + | |
| 8553 | + | |
| 8554 | + | |
| 8555 | + | |
| 8556 | + | |
| 8557 | + | |
| 8558 | + | |
| 8559 | + | |
| 8560 | + | |
| 8561 | + | |
| 8562 | + | |
| 8563 | + | |
| 8564 | + | |
| 8565 | + | |
| 8566 | + | |
| 8567 | + | |
| 8568 | + | |
| 8569 | + | |
| 8570 | + | |
| 8571 | + | |
8564 | 8572 |
| |
8565 | 8573 |
| |
8566 | 8574 |
| |
|
Lines changed: 33 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1278 | 1278 |
| |
1279 | 1279 |
| |
1280 | 1280 |
| |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
1281 | 1314 |
| |
1282 | 1315 |
| |
1283 | 1316 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
798 | 798 |
| |
799 | 799 |
| |
800 | 800 |
| |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
801 | 809 |
| |
802 | 810 |
| |
803 | 811 |
| |
|
0 commit comments
Comments
(0)