gcd()

A function for obtaining the greatest common divisor

gcd() is a system function for obtaining the greatest common divisor (the largest positive number that divides both inputs with no remainder).

gcd() was added in PostgreSQL 13.

Usage

gcd ( numeric_type, numeric_type ) → numeric_type

Change history

Examples

postgres=# SELECT gcd(8,2);
 gcd 
-----
   2
(1 row)

postgres=# SELECT gcd(8,3);
 gcd 
-----
   1
(1 row)

postgres=# SELECT gcd(8,4);
 gcd 
-----
   4
(1 row)

Categories

System function

See also

lcm()