PostgreSQL gcd() Function
The PostgreSQL gcd() function returns the greatest common divisor of two specified numbers.
If the number x is divisible by the number y, then y is a divisor of x. The greatest common divisor is the greatest of the common divisors of two numbers.
gcd() Syntax
This is the syntax of the PostgreSQL gcd() function:
gcd(x, y) -> numeric_type
Parameters
x-
Required. A number.
y-
Required. A number.
Return value
The PostgreSQL gcd() function returns the greatest common divisor of x and y.
The gcd() 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.
gcd() Examples
Here are a few examples of the gcd() function:
SELECT
gcd(3, 2) AS "gcd(3, 2)",
gcd(10, 4) AS "gcd(10, 4)",
gcd(3.3, 1.2) AS "gcd(3.3, 1.2)";
gcd(3, 2) | gcd(10, 4) | gcd(3.3, 1.2)
-----------+------------+---------------
1 | 2 | 0.3