PSQL中DECIMAL和NUMERIC数据类型之间的区别 [英] Difference between DECIMAL and NUMERIC datatype in PSQL
问题描述
在postgreSQL中使用十进制
和数字
数据类型是什么。根据参考,以下是对这些数据类型的说明。
what is the use of decimal
and numeric
datatype in postgreSQL. As per the reference the following is the explanation given to these datatypes.
Decimal,numeric --> It is a user specified precision, exact and range up to 131072 digits before the decimal point and up to 16383 digits after the decimal point.
上面的语句显示了十进制
的描述和数字
数据类型。但是,我仍然不明白这些数据类型的
确切用法是什么,以及在何处使用它而不是其他数据类型。
The above statement shows the description of decimal
and numeric
datatype. But, still I didn't understand what is the
exact use of these data type and where it is used instead of other datatypes.
非常感谢有示例的答案...
Answer with example is much appreciated...
推荐答案
<手册中的href = http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL rel = noreferrer>右侧:
类型
十进制
和数字
是等效的。两种类型都是SQL标准的一部分。
The types
decimal
andnumeric
are equivalent. Both types are part of the SQL standard.
至于为什么需要使用它,这也作了解释。手册:
As for the "why do I need to use it", this is also explained in the manual:
数字类型可以存储大量数字,并精确执行计算
(强调我的)。
如果需要带小数的数字,请使用十进制
(或数字
),如果您需要不带小数的数字,请使用整数
或 bigint
。 十进制
作为列类型的典型用法是产品价格列或利率。整数类型的典型用法是例如一列存储许多产品订购方式的列(假设您不能订购一半产品)。
If you need numbers with decimals, use decimal
(or numeric
) if you need numbers without decimals, use integer
or bigint
. A typical use of decimal
as a column type would be a "product price" column or an "interest rate". A typical use of an integer type would be e.g. a column that stores how many products were ordered (assuming you can't order "half" a product).
double
和 real
也是可以存储十进制值的类型,但它们是近似类型。这意味着您不必检索存储的值。有关详细信息,请参见: http://floating-point-gui.de/
double
and real
are also types that can store decimal values, but they are approximate types. This means you don't necessarily retrieve the value you stored. For details please see: http://floating-point-gui.de/
这篇关于PSQL中DECIMAL和NUMERIC数据类型之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!