nullif snippets

Avoiding "division by zero" in SQL queries with NULLIF

Tagged division, nullif, postgres, sql, zero  Languages sql

Use NULLIF to avoid “division by zero” in SQL queries when the divisor can have the value zero.


  col_x / NULLIF(col_y, 0) as change,

The result will be NULL when col_y contains the value zero.