Postgresql Mod Function

PostgreSQL: mod Function

In this PostgreSQL post explains how to use the PostgreSQL mod function with syntax and examples.

Description

The PostgreSQL mod function returns the remainder of n divided by m.

Syntax

The syntax for the mod function in PostgreSQL is:

mod( n, m )

Parameters or Arguments

n

A numeric value whose remainder you wish to find.

m

The number used to divide into n.

Note

  • The mod function uses the formula of n / m and the remainder is what is returned.
  • See also the div function.

Applies To

The mod function can be used in the following versions of PostgreSQL:

  • PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4

Example

Let's look at some PostgreSQL mod function examples and explore how to use the mod function in PostgreSQL.

For example:

postgres=# SELECT mod(12, 5);
 mod
-----

   2
(1 row)

postgres=# SELECT mod(12, 0.18);
 mod
------

 0.12
(1 row)

postgres=# SELECT mod(100, 3.5938);
  mod
--------

2.9674
(1 row)