PostgreSQL Tutorial

  • Home
  • Stored Procedures
  • Triggers
  • Views
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
  • Functions
    • Aggregate Functions
    • Date / Time Functions
    • String Functions
    • Math Functions
Home / PostgreSQL Math Functions / PostgreSQL MOD Function

PostgreSQL MOD Function

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

Syntax

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

1
MOD(x,y)

Arguments

The MOD() function requires two arguments:

1) x

The x argument is a number which 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.

Examples

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

1
SELECT  MOD(15,4) modulus

The result is:

1
3

The following statement also returns the same result:

1
SELECT MOD(15,-4);

See the following statement:

1
SELECT MOD(-15,4);

The remainder is a negative number:

1
-3

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

1
SELECT MOD(-15,-4);

The result is:

1
-3

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

Previous Tutorial: PostgreSQL CEIL Function
Next Tutorial: PostgreSQL FLOOR Function

PostgreSQL Math Functions

  • ABS
  • CEIL
  • MOD
  • FLOOR
  • ROUND
  • TRUNC

About PostgreSQL Tutorial

PostgreSQLTutorial.com is a website dedicated to developers and database administrators who are working on PostgreSQL database management system.

We constantly publish useful PostgreSQL tutorials to keep you up-to-date with the latest PostgreSQL features and technologies. All PostgreSQL tutorials are simple, easy-to-follow and practical.

Recent PostgreSQL Tutorials

  • How To Delete Duplicate Rows in PostgreSQL
  • PostgreSQL TO_CHAR Function
  • PostgreSQL TO_NUMBER Function
  • PostgreSQL TO_TIMESTAMP Function
  • PostgreSQL CEIL Function
  • PostgreSQL MOD Function
  • PostgreSQL FLOOR Function
  • PostgreSQL ABS Function
  • PostgreSQL TRUNC Function
  • PostgreSQL ROUND Function

More Tutorials

  • PostgreSQL Cheat Sheet
  • PostgreSQL Administration
  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

Copyright © 2017 by PostgreSQL Tutorial Website. All Rights Reserved.