Jaa


/ (slash sign) operator

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Returns dividend divided by divisor.

Syntax

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 a DIVIDE_BY_ZERO error.

Use try_divide to return NULL on division-by-zero.

Note

In Databricks Runtime, if spark.sql.ansi.enabled is false, the function returns NULL instead of a divide-by-zero error.

Examples

> SELECT 3 / 2;
 1.5

> SELECT 2L / 2L;
 1.0

> SELECT INTERVAL '3:15' HOUR TO MINUTE / 3
 0 01:05:00.000000

> SELECT 3 / 0;
 Error: DIVIDE_BY_ZERO