PostgreSQL 18 reference · Math Functions
PostgreSQL LN() Function
Return the natural logarithm (base e) of a number. exp() is the inverse.
PostgreSQL 18
Syntax
ln(x) | exp(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number (integer, numeric or double precision). |
Return value
double precision or numeric.
Examples
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.
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
Related
LOG()· Return the base-10 logarithm of a number, or the logarithm in another base with log(b, x). log10() is a synonym.POWER()· Raise a number to a power, so power(2, 10) is 1024. pow() is another name for the same function.- SQL Aggregate Functions · tutorial