pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. 7+ messages / 1 participants [nested] [flat]
* pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. @ 2021-08-05 08:40 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 7+ messages in thread From: Dean Rasheed @ 2021-08-05 08:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 ------ master Details ------- https://git.postgresql.org/pg/commitdiff/226ec49ffd78c0f246da8fceb3094991dd2302ff Modified Files -------------- src/backend/utils/adt/numeric.c | 66 ++++++++++++++++++++--------------- src/test/regress/expected/numeric.out | 32 +++++++++++++++++ src/test/regress/sql/numeric.sql | 7 ++++ 3 files changed, 76 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. @ 2021-08-05 08:40 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 7+ messages in thread From: Dean Rasheed @ 2021-08-05 08:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ecbdbdfd9056a55e38f7922565c7ce46b1321907 Modified Files -------------- src/backend/utils/adt/numeric.c | 66 ++++++++++++++++++++--------------- src/test/regress/expected/numeric.out | 32 +++++++++++++++++ src/test/regress/sql/numeric.sql | 7 ++++ 3 files changed, 76 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. @ 2021-08-05 08:40 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 7+ messages in thread From: Dean Rasheed @ 2021-08-05 08:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/a72ad63154256bd3adf1c885f8c3371e9e8ce67a 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(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. @ 2021-08-05 08:40 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 7+ messages in thread From: Dean Rasheed @ 2021-08-05 08:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/43644bd3b234091c4bfad0bf6d7d88f90c52aaf5 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(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. @ 2021-08-05 08:40 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 7+ messages in thread From: Dean Rasheed @ 2021-08-05 08:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4851940a5c000b2b2504d7add13dfbd463c1c59c 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(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. @ 2021-08-05 08:40 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 7+ messages in thread From: Dean Rasheed @ 2021-08-05 08:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. @ 2021-08-05 08:40 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 7+ messages in thread From: Dean Rasheed @ 2021-08-05 08:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ed3e1663c031e82def8c50ef31ee704777059459 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(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2021-08-05 08:40 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-08-05 08:40 pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. Dean Rasheed <dean.a.rasheed@gmail.com> 2021-08-05 08:40 pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. Dean Rasheed <dean.a.rasheed@gmail.com> 2021-08-05 08:40 pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. Dean Rasheed <dean.a.rasheed@gmail.com> 2021-08-05 08:40 pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. Dean Rasheed <dean.a.rasheed@gmail.com> 2021-08-05 08:40 pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. Dean Rasheed <dean.a.rasheed@gmail.com> 2021-08-05 08:40 pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. Dean Rasheed <dean.a.rasheed@gmail.com> 2021-08-05 08:40 pgsql: Fix division-by-zero error in to_char() with 'EEEE' format. Dean Rasheed <dean.a.rasheed@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox