PostgreSQL Tutorial: MOD Function

August 7, 2023

Summary: The PostgreSQL MOD() function performs the modulo operation that returns the remainder after the division of the first argument by the second one.

Table of Contents


The syntax of the PostgreSQL MOD() function is as follows:



The MOD() function requires two arguments:

1) x

The x argument is a number that is divided by the second one.

2) y

The y argument is the divisor.

y must not be zero (0), otherwise, the function will issue the division by zero error.

Return Value

The MOD() function returns a number whose data type is the same as the input argument.


The following example shows how to use the MOD() function to get the remainder of two integers:

SELECT  MOD(15,4) modulus

The result is:


The following statement also returns the same result:

SELECT MOD(15,-4);

See the following statement:

SELECT MOD(-15,4);

The remainder is a negative number:


Similarly, the following statement returns the same negative remainder number:

SELECT MOD(-15,-4);

The result is:


In this tutorial, you have learned how to use the PostgreSQL MOD() function to find the remainder after the division of one number by another.

See more

PostgreSQL Tutorial: Math Functions

PostgreSQL Documentation: Mathematical Functions and Operators