14

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?

Ilja
  • 993
  • 2
  • 17
  • 36

1 Answers1

27

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.

Mikhail Berlyant
  • 165,386
  • 8
  • 154
  • 230
  • 2
    Official docs here: https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#mathematical-functions – VictorGGl Mar 22 '18 at 15:11