Re: Money casting too liberal?

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Money casting too liberal?
Date: 2013-03-28 20:50:42
Message-ID: kj2af2$tif$1@gonzo.reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2013-03-28, D'Arcy J.M. Cain <darcy(at)druid(dot)net> wrote:
>
> I would like to see the type handle other situations such as foreign
> (to me) currency, etc. I suppose a positional parameter and a currency
> string setting would handle most of those issues. Technically, the
> money type is a cents type. Everything is stored as the number of
> cents. Formatting it as dollars and cents is a convenience added by
> the I/O functions.

it actually does that, if you have the locale installed you can set
LC_MONETARY to Japan and get no decimals and a Yen symbol
or to UAE and get three decimals and their currency symbol.

> Even as the author I sometimes go with numeric but there is a place for
> the type. If you are working with simple dollars and cents quantities
> and you need to do lots of calculations on them, the money type can be
> a great performance boost. The big win that money brings is that
> everything is stored as an int. That means that you don't need to
> convert data in the database to a machine representation before
> summing, averaging, etc. The machine can generally work on the data as
> it comes out of the DB.

it'd be nice to be able to do a money * numeric operation

currently multiplication is done in floating point and this can give
unexpected results.

>
> --
> D'Arcy J.M. Cain <darcy(at)druid(dot)net> | Democracy is three wolves
> http://www.druid.net/darcy/ | and a sheep voting on
> +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
> IM: darcy(at)Vex(dot)Net, VOIP: sip:darcy(at)Vex(dot)Net
>
>

--
⚂⚃ 100% natural

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Severn, Chris 2013-03-28 20:50:50 ts_tovector() to_query()
Previous Message Severn, Chris 2013-03-28 20:39:46 subscribe