Re: How useful is the money datatype?

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How useful is the money datatype?
Date: 2009-10-13 03:03:03
Message-ID: 1255402983.4702.11.camel@wallace.localnet
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 2009-10-04 at 17:12 +0100, Sam Mason wrote:

> > There is an open source library by IBM that I use in my C++ code to do
> > this, and may be it can be incorporated into PG
> >
> > it is called decNumber
> > http://speleotrove.com/decimal/decnumber.html
>
> How would this help over PG's existing numeric type?

I don't see it either. Pg's NUMERIC type is quite suitable for mixing
large and small values in calculations with reasonable precision.

test=> SELECT NUMERIC '100000000' * NUMERIC '0.00000000009';
0.00900000000

test=> SELECT NUMERIC '10000090009.000000000000000001'
/ NUMERIC '0.0000000000000000000000002';

50000450045000000000000000005000000.0000000000000000000000000

Sometimes you have to be very careful to make sure that Pg interprets
operands as NUMERIC, though, rather than as floats.

I've been extremely happy with the NUMERIC data type when working with
monetary values. For scientific use I wish there was an equivalent type
with explicit accumulation of error so I knew how much of the value was
valid, but you don't need that for financial calculations.

--
Craig Ringer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2009-10-13 03:21:05 Re:
Previous Message Craig Ringer 2009-10-13 02:32:53 Re: Is there a way to know if trigger is invoked by the code from another trigger