MOD

Returns the remainder of a division operation. MOD is also called modulo.

Behavior Type

Immutable

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:

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