+-
为什么选择实型仅在Postgres中最多打印6位数字?

我有一个Postgres表,该表的列为real类型。

[当我使用查询从该列中选择值时(例如select amount from my_table),它将舍入大于100,000的数字的值。 (它完全忽略小数部分)。对于大于1,000,000的数字,它将使用科学计数法显示它们。对于小于100,000的数字,它将去掉小数部分,这样整体上最多只能打印出6位数字(例如,1,000.12345变为1,000.12)。

仅当我将值转换为双精度(使用CAST(amount as double precision)时,它才开始表现出预期的效果,并打印出所有存储的十进制数字。

有人知道为什么Postgres会以这种方式行事吗?

0
投票

答案可能在PostgreSQL源代码postgres / src / fe_utils / print.c中。对format_numeric_locale的评论说:

/*
 * Format a numeric value per current LC_NUMERIC locale setting
 *
 * Returns the appropriately formatted string in a new allocated block,
 * caller must free.
 *
 * setDecimalLocale() must have been called earlier.
 */

另请参见setDecimalLocale中的注释。