]> granicus.if.org Git - postgresql/commit
Fix loss of fractional digits for large values in cash_numeric().
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 26 Jul 2019 15:59:00 +0000 (11:59 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 26 Jul 2019 15:59:00 +0000 (11:59 -0400)
commit13e493cf68a4ed8a54e974c41470fab43676e67c
treed4aaccf91b844987e2d22a1c882c0d2c1fa2cdaf
parent4583605e6d1f2b95a61dfe0c1fdfba99a88e3c4a
Fix loss of fractional digits for large values in cash_numeric().

Money values exceeding about 18 digits (depending on lc_monetary)
could be inaccurately converted to numeric, due to select_div_scale()
deciding it didn't need to compute any fractional digits.  Force
its hand by setting the dscale of one division input to equal the
number of fractional digits we need.

In passing, rearrange the logic to not do useless work in locales
where money values are considered integral.

Per bug #15925 from Slawomir Chodnicki.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/15925-da9953e2674bb5c8@postgresql.org
src/backend/utils/adt/cash.c
src/test/regress/expected/money.out
src/test/regress/sql/money.sql