Re: dividing money by money

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Andy Balholm" <andy(at)balholm(dot)com>,<pgsql-hackers(at)postgresql(dot)org>
Subject: Re: dividing money by money
Date: 2010-07-16 13:39:09
Message-ID: 4C401AAD02000025000336F4@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-www

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> * I didn't like this bit in cash_numeric():
>
> result->n_sign_dscale = NUMERIC_SIGN(result) | fpoint;
>
> Not only is that unwarranted chumminess with the implementation of
> numeric, it's flat-out wrong. If the result isn't exactly the
> right number of digits (say, it's 12.33999999 instead of the
> desired 12.34) this just hides the extra digits, it doesn't make
> the result correct. The right way is to use numeric_round(),
> which not only sets the dscale where we want it but rounds off any
> inaccuracy that might have crept in from the division.

Thanks. Duly noted.

> * The cast functions were marked immutable, which is wrong because
> they depend on the setting of lc_monetary. The right marking is
> "stable".

Is there any impact of the change to lc_monetary which would matter
besides the number of decimal positions? If that changes, isn't
every money amount in the database instantly made incorrect? If so,
I'm dubious that marking this as stable is worthwhile -- if someone
is making a change like that, they will need to update all money
amounts in the database; reindexing would be the least of their
problems. Or am I missing some other effect?

-Kevin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-07-16 13:49:28 Re: ERROR: argument to pg_get_expr() must come from system catalogs
Previous Message Thom Brown 2010-07-16 13:17:34 Re: reducing NUMERIC size for 9.1

Browse pgsql-www by date

  From Date Subject
Next Message Kevin Grittner 2010-07-16 13:55:19 Re: dividing money by money
Previous Message Peter Eisentraut 2010-07-16 05:17:43 Re: dividing money by money