postgres division by zero code example
Example 1: division by zero postgres
-- avoid division error in Postgres
value/NULLIF(col, 0) -- if col == 0, NULL will be returned
value/COALESCE(NULLIF(col, 0), 1) -- if col == 0, value will be returned
Example 2: postgres : ERROR: division by zero
SELECT 1.0 / NULLIF(column_that_may_be_zero, 0)