Postgresql – Handling differences between MS-SQL and PostgreSQL money datatypes

moneypgadminpostgresqlpostgresql-9.4

This is a follow-up/ to my previous question Is it possible to insert un-formatted data for money data type in PostgreSQL

  1. I could read money data by typecasting it into numeric

     SELECT '52093.89'::money::numeric
    

    Will it give inconsistent data, rounded etc.. ?

  2. As per ISO standard, the money datatype size is (19,4) but why PostgreSQL returns size as 2147483647? Is this size locale dependent?

  3. Is it a good idea to use the money datatype to store/retrieve locale specific values? If not, when is the money datatype best suitable?

I have to use the money datatype for certain cases. My worry is will I get any problems if I treat money datatype values as decimal values?

I don't bother about locale specific values such as symbol, digit, and decimal grouping etc.. Can I store money datatype values as per lc_monetary settings and reading by typecasting it to numeric?

Best Answer

In Postgres, the cast from money to numeric is exact, immutable and does not round.

In SQL Server the data type MONEY uses 8 bytes to store a values in any currency in the numeric range from -922337203685477.5808 to 922337203685477.5807.
Matches numeric(19,4).

In PostgreSQL the data type money also occupies 8 bytes but the allowed range is -92233720368547758.08 to +92233720368547758.07. Same precision, but different scale by default (without LC_MONETARY setting other than 'C') - only two fractional digits.
Matches numeric(19,2).

But, quoting the manual:

The fractional precision is determined by the database's lc_monetary setting.

I updated the tag info for accordingly.

As @a_horse commented (repeatedly), money is not defined by the SQL standard.

And it's pretty much consensus around here to stay away from the money data type if you can.