div
operator
Applies to: Databricks SQL Databricks Runtime
Returns the integral part of the division of divisor
by dividend
.
Syntax
divisor div dividend
Arguments
divisor
: An expression that evaluates to a numeric or interval.dividend
: A matching interval type ifdivisor
is an interval, a numeric otherwise.
Interval is supported since: Databricks Runtime 10.1
Returns
A BIGINT
If dividend
is 0
, INTERVAL '0' SECOND
or INTERVAL '0' MONTH
the operator raises a DIVIDE_BY_ZERO error.
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 div 2;
1
> SELECT -5.9 div 1;
-5
> SELECT -5.9 div 0;
Error: DIVIDE_BY_ZERO
> SELECT INTERVAL '100' HOUR div INTERVAL '1' DAY;
4
Related functions
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for