In this PostgreSQL post explains how to use the PostgreSQL div function with syntax and examples.
The PostgreSQL div function is used for integer division where n is divided by m and an integer value is returned.
The syntax for the div function in PostgreSQL is:
div(n, m)
A numeric value that will be divided by m.
The number used to divide into n.
The div function can be used in the following versions of PostgreSQL:
Let's look at some PostgreSQL div function examples and explore how to use the div function in PostgreSQL.
For example:
postgres=# SELECT div(9, 2);
div
-----
4
(1 row)
postgres=# SELECT div(8, 2);
div
-----
4
(1 row)
postgres=# SELECT div(10.5, 3.1);
div
-----
3
(1 row)
postgres=# SELECT div(10.5, -3.1);
div
-----
-3
(1 row)