【问题标题】:Correct use of COALESCE() in BigQuery在 BigQuery 中正确使用 COALESCE()
【发布时间】:2020-01-13 11:47:14
【问题描述】:

我正在运行以下脚本:

select COALESCE(test1,test2,test3)
from (select null as test1,'' as test2,'fdsda' as test3)

并收到以下错误:

对于参数类型的函数 COALESCE 没有匹配的签名:INT64, 字符串,字符串。支持的签名:COALESCE([ANY, ...]) at [1:8]

知道这个错误的原因吗?

【问题讨论】:

    标签: google-bigquery coalesce


    【解决方案1】:

    使用COALESCE 时,您必须提供相同类型的参数。 例如,如果第一个参数是 STRING,那么其他参数也应该是 STRING。 在您的情况下,您尝试提供 INTEGER 作为第一个参数,并为其他参数提供 STRING。

    希望对你有帮助

    【讨论】:

    • 很高兴知道 NULL 是一个 int 类型 :)
    【解决方案2】:

    使用

    select COALESCE(test1,test2,test3) from (select cast(null as string) as test1,'' as test2,'fdsda' as test3)
    

    无论如何,我同意 rmesteves - 合并中的不同类型没有意义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-09
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多