postgresql/src/backend/utils
Dean Rasheed a72ad63154 Fix division-by-zero error in to_char() with 'EEEE' format.
This fixes a long-standing bug when using to_char() to format a
numeric value in scientific notation -- if the value's exponent is
less than -NUMERIC_MAX_DISPLAY_SCALE-1 (-1001), it produced a
division-by-zero error.

The reason for this error was that get_str_from_var_sci() divides its
input by 10^exp, which it produced using power_var_int(). However, the
underflow test in power_var_int() causes it to return zero if the
result scale is too small. That's not a problem for power_var_int()'s
only 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 to
compute 10^exp directly, with no rscale limit. This also allows 10^exp
to be computed more efficiently, without any numeric multiplication,
division or rounding.

Discussion: https://postgr.es/m/CAEZATCWhojfH4whaqgUKBe8D5jNHB8ytzemL-PnRx+KCTyMXmg@mail.gmail.com
2021-08-05 09:29:13 +01:00
..
adt Fix division-by-zero error in to_char() with 'EEEE' format. 2021-08-05 09:29:13 +01:00
cache Fix assign_record_type_typmod(). 2021-07-10 10:27:27 -07:00
error Log the location field before any backtrace 2020-07-10 08:31:48 +02:00
fmgr Fix broken ruleutils support for function TRANSFORM clauses. 2021-01-25 13:03:11 -05:00
hash Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
init Fix assorted issues in backend's GSSAPI encryption support. 2020-12-28 17:44:17 -05:00
mb Dial back -Wimplicit-fallthrough to level 3 2020-05-13 15:31:14 -04:00
misc Set pg_setting.pending_restart when pertinent config lines are removed 2021-07-27 15:44:12 -04:00
mmgr Restore the portal-level snapshot after procedure COMMIT/ROLLBACK. 2021-05-21 14:03:53 -04:00
resowner Improve performance of "simple expressions" in PL/pgSQL. 2020-03-26 18:58:57 -04:00
sort Robustify tuplesort's free_sort_tuple function 2021-07-13 13:28:19 +12:00
time Revive "snapshot too old" with wal_level=minimal and SET TABLESPACE. 2021-01-30 00:13:58 -08:00
.gitignore Rearrange makefile rules for running Gen_fmgrtab.pl. 2018-05-03 17:54:18 -04:00
errcodes.txt Make SQL/JSON error code names match SQL standard 2020-04-30 09:34:54 +02:00
Gen_dummy_probes.pl Emit dummy statements for probes.d probes when disabled 2021-05-10 13:56:21 +02:00
Gen_dummy_probes.sed Emit dummy statements for probes.d probes when disabled 2021-05-10 13:56:21 +02:00
Gen_fmgrtab.pl Use perl warnings pragma consistently 2020-04-13 11:55:45 -04:00
generate-errcodes.pl Update copyrights for 2020 2020-01-01 12:21:45 -05:00
Makefile Update copyrights for 2020 2020-01-01 12:21:45 -05:00
probes.d Update copyrights for 2020 2020-01-01 12:21:45 -05:00