应该使用哪种PostgreSQL列类型来存储Java BigDecimal? [英] Which PostgreSQL column type should be used to store a Java BigDecimal?
问题描述
我应该使用哪种PostgreSQL列类型来存储Java BigDecimal?
What PostgreSQL column type should I use to store a Java BigDecimal?
推荐答案
请参见 PostgreSQL数据类型-也许数字,它可以用作任意精度类型(这是PostgreSQL的扩展名)。
See PostgreSQL datatypes - perhaps Numeric, which can act as an arbitrary precision type (this is a PostgreSQL extension).
...不带任何精度或小数位数的列会在其中存储任何精度和小数位数的数值
...without any precision or scale creates a column in which numeric values of any precision and scale can be stored, up to the implementation limit on precision.
我不完全确定精度实施限制是什么不过。从来没有尝试过真的大量。如果达到限制,则可以回退到 text
。但是,我怀疑在那之前还会有其他重大问题;-)如果您希望减少存储量,请指定精度和/或小数位数为数字
。
I am not entirely sure what "implementation limit on precision is", though. Have never tried really large numbers. If the limit is reached, then a fallback to text
is possible. But, I suspect there will be significant other issues before then ;-) If you wish to store less, then specify a precision and/or scale to numeric
.
编辑,限制为精度为1000个十进制数字(来自同一链接):
Edit as sjr pointed out, the restriction is 1000 decimal digits of precision (from the same link):
数字类型可以存储精度高达1000位的数字(在当前的实现中)并精确地执行计算。特别建议在需要精确度的情况下存储货币金额和其他数量...
The type numeric can store numbers with up to 1000 digits of precision [in currentl implementations] and perform calculations exactly. It is especially recommended for storing monetary amounts and other quantities where exactness is required...
如果需要 more 精度-尽管手头有一个更大的问题-然后数字列将不适合(就其本身而言)。但这实际上更像是一个非常极端的假设,并且可能不会发挥限制作用。
If more precision is needed - despite having a much bigger problem at hand - then a numeric column will not be suitable (by itself). But this is really more of a very extreme "what if" and likely does not play a limiting role.
这篇关于应该使用哪种PostgreSQL列类型来存储Java BigDecimal?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!