try_divide function

Returns dividend divided by divisor, or NULL if divisor is 0.

Since: Databricks Runtime 10.0

Syntax

try_divide(dividend, divisor)

Arguments

  • dividend: A numeric or INTERVAL expression.

  • divisor: A numeric expression.

Returns

If both dividend and divisor are DECIMAL, the result is DECIMAL.

If dividend is a year-month interval, the result is an INTERVAL YEAR TO MONTH.

If divident is a day-time interval, the result is an INTERVAL DAY TO SECOND.

In all other cases, a DOUBLE.

If the divisor is 0, the operator returns NULL.

Examples

> SELECT try_divide(3, 2);
 1.5

> SELECT try_divide(2L, 2L);
 1.0

> SELECT try_divide(INTERVAL '3:15' HOUR TO MINUTE, 3);
 0 01:05:00.000000

> SELECT try_divide(3 , 0)
  NULL