Re: Money casting too liberal? - Mailing list pgsql-general

From David Johnston
Subject Re: Money casting too liberal?
Date
Msg-id 1364428094619-5749933.post@n5.nabble.com
Whole thread Raw
In response to Money casting too liberal?  (Steve Crawford <scrawford@pinpointresearch.com>)
List 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.


pgsql-general by date:

Previous
From: "Severn, Chris"
Date:
Subject: subscribe
Next
From: aasat
Date:
Subject: Re: UNLOGGED TEMPORARY tables?