w3resource

PostgreSQL DIV() function

DIV() function

The PostgreSQL DIV() function is used to return the integer quotient of a division as specified in the argument. This means it performs division between two numbers and returns the whole number part of the result, discarding any remainder.

Uses of DIV() Function
  • Integer Division: To perform integer division where only the quotient is needed.

  • Mathematical Simplification: To simplify mathematical operations in queries that require the quotient of a division.

  • Financial Calculations: Useful in financial calculations where fractional parts are not required.

  • Grouping and Batching: Can be used to determine the number of complete groups or batches when dividing items into groups.

Syntax:

div()

PostgreSQL Version: 9.3

Pictorial presentation of PostgreSQL DIV() function

pictorial presentation of PostgreSQL DIV() function

Example: PostgreSQL DIV() function

Code:

SELECT DIV(19,3) AS "Quotient";

Sample Output:

 Quotient
----------
        6
(1 row)

Example: PostgreSQL DIV() function using negative value

Code:

SELECT DIV(-27,5) AS "Quotient";

Sample Output:

 Quotient
----------
       -5
(1 row)ssss

Previous: DEGREES function
Next: EXP function



Follow us on Facebook and Twitter for latest update.