【问题标题】:calculations imprecise, Redshift, postgresql计算不精确,Redshift,postgresql
【发布时间】:2015-10-15 13:42:06
【问题描述】:

我想知道为什么即使我进行了类型转换,我也会得到不精确的结果。

select (sum(sellerid)::decimal/count(*)::decimal) from winsales

这是 Redshift 文档中的示例。 http://docs.aws.amazon.com/redshift/latest/dg/r_Window_function_examples.html

它应该给出类似 2.454545 的值,但它会将值截断为 2.45。 为什么会这样,我怎样才能提高精度?尝试了 float4 和 float8 并得到相同的结果。

【问题讨论】:

  • 也许尝试decimal(presicion, scale)(或数字),而不是使用固定的精度和比例。
  • 刚刚试过。它什么都没有改变,在点之后仍然是 2 位数。
  • 那可能是你的SQL客户端限制了小数位数。
  • 我正在为 postgresql 使用 SQL Workbench。你知道如何解除限制以查看真实数据而不是重新格式化吗?

标签: postgresql amazon-redshift


【解决方案1】:

试试这个:

select (sum(sellerid*1.0)/count(*)) from winsales

【讨论】:

    猜你喜欢
    • 2019-07-31
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 2013-10-02
    • 2016-12-01
    • 2016-06-01
    • 2018-01-21
    • 2011-02-12
    相关资源
    最近更新 更多