PostgreSQL 18 reference · Math Functions

PostgreSQL MOD() Function

Return the remainder of dividing one number by another; x % y does the same. The sign follows the dividend.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

mod(y, x)  |  y % x

Parameters

ParameterDescription
y The dividend.
x The divisor (not 0).

Return value

The remainder.

Examples

Remainders
SELECT mod(10, 3) AS a, -10 % 3 AS b, mod(7.5, 2) AS c;

Output

 a | b  |  c
---+----+-----
 1 | -1 | 1.5
(1 row)

Run this on your computer — see “Get Started” for setup.

Every fourth row
SELECT order_id FROM orders WHERE order_id % 4 = 0;

Output

 order_id
----------
        4
        8
       12
(3 rows)

Run this on your computer — see “Get Started” for setup.

In other languages

Was this page helpful?