BigQuery - IFERROR for standardSQL

Ilja picture Ilja · Mar 18, 2018 · Viewed 11.8k times · Source

I'm about to migrate queries from Legacy to Standard in BQ. In Legacy I used to have x/y returning null if y=0, however, I'm stuck in StandardSQL with the error:

Error: division by zero

I'd like to apply something like IFERROR(x/y,null)

Is it available in StandardSQL?

Answer

Mikhail Berlyant picture Mikhail Berlyant · Mar 18, 2018

In standard SQL you can use SAFE_DIVIDE(x, y)
It is an equivalent to the division operator (/). Returns NULL if an error occurs, such as division by zero.