pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix loss of fractional digits for large values in cash_numeric()
Date: Fri, 26 Jul 2019 16:00:46 +0000
Message-ID: <E1hr2eE-0004RF-RZ@gemulon.postgresql.org> (raw)

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

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/fa854112fc3d5fae1da071bd647eb777eb584c2e

Modified Files
--------------
src/backend/utils/adt/cash.c        | 58 ++++++++++++++++++++++++-------------
src/test/regress/expected/money.out | 16 +++++++++-
src/test/regress/sql/money.sql      |  6 +++-
3 files changed, 58 insertions(+), 22 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1hr2eE-0004RF-RZ@gemulon.postgresql.org>
Permalink:  ../E1hr2eE-0004RF-RZ@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1hr2eE-0004RF-RZ@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix loss of fractional digits for large values in cash_numeric()
  In-Reply-To: <E1hr2eE-0004RF-RZ@gemulon.postgresql.org>
  References: <E1hr2eE-0004RF-RZ@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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