BigQuery - 标准SQL的IFERROR

Ilj*_*lja 8 legacy-code google-bigquery

我即将在BQ中将查询从Legacy迁移到Standard.在Legacy中,我曾经有过x/y返回,但是,null如果y=0我因为错误而陷入StandardSQL:

错误:除以零

我想申请类似的东西 IFERROR(x/y,null)

它在StandardSQL中可用吗?

Mik*_*ant 14

在标准SQL中,您可以使用SAFE_DIVIDE(x, y)
它等同于除法运算符(/).如果发生错误,则返回NULL,例如除以零.

  • 官方文档在这里:https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#mathematical-functions (2认同)