From: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. |
Date: | 2021-08-05 08:40:55 |
Message-ID: | E1mBYvv-0003Sr-W5@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
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
Branch
------
REL_10_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/661558bc35c7d0cd10640e7a2a065391ec769a7d
Modified Files
--------------
src/backend/utils/adt/numeric.c | 66 ++++++++++++++++++++---------------
src/test/regress/expected/numeric.out | 33 ++++++++++++++++++
src/test/regress/sql/numeric.sql | 8 +++++
3 files changed, 78 insertions(+), 29 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Dean Rasheed | 2021-08-05 08:40:56 | pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. |
Previous Message | Michael Paquier | 2021-08-05 06:02:56 | Re: pgsql: Enable TAP tests of pg_receivewal for ZLIB on Windows, take thre |