PostgreSQL lcm() Function

The PostgreSQL lcm() function returns the least common multiple of two specified numbers.

If the number x is divisible by the number y, then x is a multiple of y. The least common multiple is the smallest of the common multiples of two numbers.

lcm() Syntax

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

lcm(x, y) -> numeric_type

Parameters

x

Required. A number.

y

Required. A number.

Return value

The PostgreSQL lcm() function returns the least common multiple of x and y.

The lcm() 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.

lcm() Examples

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

SELECT
    lcm(3, 2) AS "lcm(3, 2)",
    lcm(10, 4) AS "lcm(10, 4)",
    lcm(3.3, 1.2) AS "lcm(3.3, 1.2)";
 lcm(3, 2) | lcm(10, 4) | lcm(3.3, 1.2)
-----------+------------+---------------
         6 |         20 |          13.2