BigQuery是否支持ANSI SQL 2011标准中定义的NUMERIC和DECIMAL数据类型?

时间:2017-08-24 13:16:16

标签: google-bigquery

许多应用程序,包括那些处理有关货币,货币和其他财务信息的存储数据的应用程序,都依赖于固定精度的十进制数据类型。在SQL中,这些存储在具有NUMERIC或DECIMAL类型的列中。

是否有支持固定精度小数的BigQuery数据类型?

2 个答案:

答案 0 :(得分:3)

BigQuery支持NUMERIC data type,它在撰写本文时处于测试阶段。它有38位精度数字,9位数的分数精度。您可以在精确度很重要的场景中使用它,例如获取货币值的总和或平均值。例如:

WITH Transactions AS (
  SELECT DATE '2018-05-15' AS transaction_date, NUMERIC '12.34' AS transaction_amount UNION ALL
  SELECT DATE '2018-05-01', NUMERIC '100.11' UNION ALL
  SELECT DATE '2018-05-06', NUMERIC '54.00' UNION ALL
  SELECT DATE '2018-05-02', NUMERIC '999.99' UNION ALL
  SELECT DATE '2018-05-03', NUMERIC '1234.56' UNION ALL
  SELECT DATE '2018-05-04', NUMERIC '99.00'
)
SELECT
  SUM(transaction_amount) AS total_sales,
  ROUND(AVG(transaction_amount), 2) AS average_sale,
  ARRAY_AGG(
    STRUCT(transaction_date AS date, transaction_amount AS amount)
    ORDER BY transaction_amount DESC LIMIT 3
  ) AS top_sales
FROM Transactions;

答案 1 :(得分:0)

BigQuery 支持具有

BIGNUMERIC类型

精度: 76.76(第 77 位部分)

规模: 38

最小值: -5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38 最大: 5.7896044618658097711785492504343953926634992332820282019728792003956564819967E+38