Teradata ZEROIFNULL in Snowflake, Databricks and BigQuery
Snowflake keeps ZEROIFNULL, and Databricks Runtime 16.0 added it too. BigQuery has no such function; use IFNULL(x, 0) or COALESCE(x, 0).
Teradata function: ZEROIFNULL(arg) · Teradata docs
Equivalents
| Target | Support | Syntax | Notes | Source |
|---|---|---|---|---|
| Snowflake | Same name | ZEROIFNULL(expr) | Returns 0 if the argument is NULL, otherwise the argument. | Snowflake docs |
| Databricks | Same name | zeroifnull(expr) | Databricks Runtime 16.0 and above; the docs do not list it for Databricks SQL warehouses, where coalesce(expr, 0) works everywhere. | Databricks docs |
| BigQuery | Rewrite | IFNULL(expr, 0) | COALESCE(expr, 0) is equivalent. | BigQuery docs |
Behavior differences to check
Databricks
- On Databricks SQL warehouses or runtimes before 16.0, write coalesce(expr, 0) instead.
Examples
Treat missing sales as zero
SELECT store_id, ZEROIFNULL(sales) AS sales FROM daily_sales;SELECT store_id, ZEROIFNULL(sales) AS sales FROM daily_sales;SELECT store_id, zeroifnull(sales) AS sales FROM daily_sales;SELECT store_id, IFNULL(sales, 0) AS sales FROM daily_sales;