MOD

Syntax

MOD(num1, num2);

Overview

MODis a function that returns the remainder of num1 divided by num2. If num2 is 0, it returns num1.

This function returns a result that differs from the traditional Modulus function when num1 or num2 is negative.

The traditional Modulus function is as follows.

num1 - num2 * FLOOR(num1/num2)
Arguments
Description

num1, num2

num1 and num2 must be numeric types or types that can be converted to numeric types. num1 and num2 are converted to the type with the higher numeric precedence of the two types, and are also returned as that type.

Example

SELECT MOD(-11, 4), MOD(11, -4);
 mod | mod 
-----+-----
  -3 |   3

Last updated