Re: Money casting too liberal?

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Money casting too liberal?
Date: 2013-03-27 23:48:14
Message-ID: 1364428094619-5749933.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Steve Crawford wrote
>
> select ',123,456,,7,8.1,0,9'::money;
> money
> ----------------
> $12,345,678.11

As an end-user it would seem since a comma (or whatever the locale defines
as a group separator) carries no significant information - it is purely
aesthetic - that ignoring all commas during input conversion is a reasonable
behavior. The placement of the commas is mere convention and not formally
encoded in the locale. While for money the point is usually moot a long
sequence fractional numbers would benefit equally from having a group
separator just as the long sequence of whole numbers does traditionally.

Steve Crawford wrote
> Somewhat more worrisome is the fact that it automatically rounds input
> (away from zero) to fit.
>
> select '123.456789'::money;
> money
> ---------
> $123.46

This too seems to be useful since, for instance, if you end up dividing a
money by a unit - to get a per-unit value - the end result should be in the
same currency and would have to be rounded to the maximum precision of the
currency involved.

Given that neither behavior is overtly wrong if during data entry you feel a
more stringent input string is required you will need to use a regular
expression to assert that constraint.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Money-casting-too-liberal-tp5749919p5749933.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sergey Konoplev 2013-03-28 03:49:23 Re: bloating index, pg_restore
Previous Message Clemens Eisserer 2013-03-27 22:16:58 Re: Is there any way to listen to NOTIFY in php without polling?