Note, that you also need to find the corresponding data type in the programming language you use. Storing integer number of minimal units can lead to the need of rescaling values in the future if you need to change the precision.Storing prices of small units of goods (probably as a result of conversion from another currency) or having accumulators (accumulate 10% fee from 1 cent transactions until the sum reaches 1 cent) can require using more decimals than are defined for a currency.The number of decimals can change over time due to inflation. Cryptocurrencies have up to 18 decimals (ETH). Types of currencies you support (they can have different number of decimals).To find out the needed precision you need to consider the following: ![]() cents) and you have troubles handling decimals in your programming language. Decimal with precision = 0 can be the option if you want to store the integer number of currency minor units (e.g. My personal recommendation is decimal with the precision according to your needs. That's more efficient than any other of the mentioned options. Personally, I like to store currency as integer representing Cents if fractional Cents never occur (basically where money makes sense). This works by using the CONVERT function to convert the number from MONEY to a VARCHAR with a style of 1, which adds the commas and also a decimal point and. It is especially recommended for storing monetary amounts and other The type numeric can store numbers with a very large number of digits. The advantage over numeric is performance.ĭecimal is just an alias for numeric in Postgres, and widely used for monetary data, being an "arbitrary precision" type. The Postgres Wiki suggests to largely avoid it, except for those narrowly defined cases. Jasper Report: unable to get value for field 'x' of class ''īasically, money has its (very limited) uses.Related answer (and comments!) about improvements in recent releases: select (89900::float8 / 100.0), 899::money -money89900, (src/backend/utils/adt/cash. ![]() ![]() SELECT CAST ( 44 AS bit (5) ) -CAST TO BIT. If the money type was officially "discouraged" PostgreSQL would say so in the manual - which it doesn't.įor a more official source, read this thread in pgsql-general (from just this week!), with statements from core developers including D'Arcy J.M. In Postgresql, to cast or convert from int to bit use the below command. It dates to 2011 and I don't even recognize the authors.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |