BigQuery中的NUMERIC和FLOAT有什么区别? [英] What is the difference between NUMERIC and FLOAT in BigQuery?

查看:208
本文介绍了BigQuery中的NUMERIC和FLOAT有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了以下文档: https://cloud.google.com/bigquery/docs/reference /standard-sql/data-types https://cloud.google.com/bigquery/pricing#data

I read the docs: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types https://cloud.google.com/bigquery/pricing#data

我知道FLOAT是8个字节,而NUMERIC是16个字节 那是唯一的区别吗? 文档说NUMERIC的范围可以从-99999999999999999999999999999.99999999999999999999999999999999999999.999999999,但是没有指定FLOAT的范围.

I know that FLOAT is 8 bytes while NUMERIC is 16 bytes Is that the only difference? The docs says that NUMERIC can range -99999999999999999999999999999.999999999 to 99999999999999999999999999999.999999999 but it doesn't specify the range for FLOAT.

推荐答案

我喜欢当前的答案.我想添加这个作为为什么需要NUMERIC的证明:

I like the current answers. I want to add this as a proof of why NUMERIC is necessary:

SELECT 
  4.35 * 100 a_float
  , CAST(4.35 AS NUMERIC) * 100 a_numeric

这不是错误-这正是 IEEE定义浮点数的处理方式.同时NUMERIC表现出的行为更接近人类的期望.

This is not a bug - this is exactly how the IEEE defines floats should be handled. Meanwhile NUMERIC exhibits behavior closer to what humans expect.

为进一步证明NUMERIC有用性,此答案显示NUMERIC如何处理对于JavaScript无法正常处理的数字太大.

For another proof of NUMERIC usefulness, this answer shows how NUMERIC can handle numbers too big for JavaScript to normally handle.

在将此问题归咎于BigQuery之前,您可以检查大多数其他编程语言是否会执行相同的操作. Python,例如:

Before you blame BigQuery for this problem, you can check that most other programming languages will do the same. Python, for example:

这篇关于BigQuery中的NUMERIC和FLOAT有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆