PostgreSQL div() Function

The PostgreSQL div() function divides the specified two numbers and returns the integer quotient.

div() Syntax

This is the syntax of the PostgreSQL div() function:

div(y, x) -> integer

Parameters

y

Required. The dividend.

x

Required. The divisor.

Return value

The PostgreSQL div() function returns the integer quotient of y divided by x, that is the integer part of y/x.

The div() function will return NULL if the argument is NULL.

PostgreSQL will give an error if you supply a parameter that is not a numeric type.

div() Examples

Here are a few examples of the div() function:

SELECT
    div(3, 2) AS "div(3, 2)",
    div(3.3, 1.2) AS "div(3.3, 1.2)";
 div(3, 2) | div(3.3, 1.2)
-----------+---------------
         1 |             2

Here,

  • 3 / 2 = 1.5, the integer part of 1.5 is 1, so div(3, 2) returned 1.
  • 3.3 / 1.2 = 2.75, the integer part of 2.75 is 2, so div(3.3, 1.2) returned 2.