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
Syntax
mod(y, x) | y % x
Parameters
| Parameter | Description |
|---|---|
y |
The dividend. |
x |
The divisor (not 0). |
Return value
The remainder.
Examples
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.
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
MOD()· SQLite
Related
DIV()· Return the integer quotient of y / x, truncated toward zero, for numeric values. Integer / integer already truncates.- SQL Aggregate Functions · tutorial