PostgreSQL 18 reference · Math Functions

PostgreSQL LN() Function

Return the natural logarithm (base e) of a number. exp() is the inverse.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

ln(x)  |  exp(x)

Parameters

ParameterDescription
x A number (integer, numeric or double precision).

Return value

double precision or numeric.

Examples

Natural logarithm
SELECT ln(1) AS a, round(ln(10)::numeric, 4) AS b, round(exp(1)::numeric, 5) AS e;

Output

 a |   b    |    e
---+--------+---------
 0 | 2.3026 | 2.71828
(1 row)

Run this on your computer — see “Get Started” for setup.

Doubling time
SELECT round((ln(2) / ln(1.07))::numeric, 1) AS years_to_double_at_7pct;

Output

 years_to_double_at_7pct
-------------------------
                    10.2
(1 row)

Run this on your computer — see “Get Started” for setup.

In other languages

Was this page helpful?