代码之家  ›  专栏  ›  技术社区  ›  Stewart_R

BigQuery标准SQL:将值设置为正或负无穷大

  •  1
  • Stewart_R  · 技术社区  · 5 年前

    我注意到 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        |
    +---+-----+-------------+
    

    1 回复  |  直到 5 年前
        1
  •  3
  •   Gordon Linoff    5 年前

    您可以使用 cast() :

    select is_inf(cast('Infinity' as float64))
    

    或:

    select is_inf(cast('inf' as float64))
    

    documentation 是:

    以下不区分大小写的字符串可以显式转换为float:

    • “inf”或“+inf”
    • “-inf”