MOD
Returns the remainder of a division operation. MOD is also called modulo
.
Behavior Type
Syntax
MOD(
expression1,
expression2 )
Parameters
expression1 |
Specifies the dividend (INTEGER, NUMERIC, or FLOAT) |
expression2 |
Specifies the divisor (type same as dividend) |
Notes
When computing mod(N,M), the following rules apply:
- If either N or M is the null value, then the result is the null value.
- If M is zero, then an exception condition is raised: data exception — division by zero.
-
Otherwise, the result is the unique exact numeric value R with scale 0 (zero) such that all of the following are true:
- R has the same sign as N.
- The absolute value of R is less than the absolute value of M.
- N = M * K + R for some exact numeric value K with scale 0 (zero).
Examples
SELECT MOD(9,4); mod ----- 1 (1 row)
SELECT MOD(10,3); mod ----- 1 (1 row)
SELECT MOD(-10,3); mod ----- -1 (1 row)
SELECT MOD(-10,-3); mod ----- -1 (1 row)
SELECT MOD(10,-3); mod ----- 1 (1 row)
MOD(<float>, 0)
gives an error:
=> SELECT MOD(6.2,0); ERROR: numeric division by zero