One thing I’d check first is whether the issue is actually the CASE statement or the data type of the column being updated.
In BigQuery, NULL is typeless until it’s cast or inferred. If you’re replacing a numeric 0 with NULL, the expression returned by the CASE must still resolve to a consistent type. For example:
CASE
WHEN column_name = 0 THEN NULL
ELSE column_name
END
usually works because BigQuery can infer the type from column_name. But if the column is being transformed alongside other expressions, or if multiple branches return different types, BigQuery may reject the update.
Another thing to verify is whether you’re updating a partitioned or clustered table with constraints, or attempting to write a value that doesn’t match the target schema.
My debugging approach would be:
-
Run the CASE expression in a SELECT first.
-
Confirm the output type using TYPEOF().
-
Check whether all branches of the CASE return the same data type.
-
Verify that the target column allows NULL values.
In my experience, most “replace 0 with NULL” update failures end up being type-resolution issues rather than a problem with the CASE logic itself.
What exact error message is BigQuery returning? That usually points directly to whether it’s a typing, schema, or update constraint issue.