我从docs for BigQuery Standard SQL Mathematical functions注意到,我们可以使用IS_INF()
函数来测试数字“是否为无穷大”:
WITH demo_tbl AS (
SELECT 1 AS val UNION ALL
SELECT 100 AS val
)
SELECT
val,
IS_INF(val) as is_infinity
FROM demo_tbl
输出:
+---+-----+-------------+
| | val | is_infinity |
+---+-----+-------------+
| 0 | 1 | False |
| 1 | 100 | False |
+---+-----+-------------+
但是可以使用某个常数值或关键字明确地将值设置为正无穷大还是负无穷大?
也许是这样的:
WITH demo_tbl AS (
SELECT 1 AS val UNION ALL
SELECT +inf AS val -- <-- THIS doesnt work
)
SELECT
val,
IS_INF(val) as is_infinity
FROM demo_tbl
以便提供与此类似的所需输出:
+---+-----+-------------+
| | val | is_infinity |
+---+-----+-------------+
| 0 | 1 | False |
| 1 | inf | True |
+---+-----+-------------+
我尽可能地搜索了文档,并为此找到了一个Google,但找不到答案。
答案 0 :(得分:1)
您可以使用cast()
创建值:
select is_inf(cast('Infinity' as float64))
或:
select is_inf(cast('inf' as float64))
埋在documentation中的是:
没有NaN或无穷大的字面表示,但是 以下不区分大小写的字符串可以显式转换为float:
- “ NaN”
- “ inf”或“ + inf”
- “-inf”