PostgreSQL ln() Function
The PostgreSQL ln()
function returns the natural logarithm of the number specified by the argument.
ln()
Syntax
This is the syntax of the PostgreSQL ln()
function:
ln(numeric_value) -> double precision
Parameters
numeric_value
-
Required. A number whose logarithm needs to be obtained.
Return value
The PostgreSQL ln()
function returns the natural logarithm of the number specified by the argument.
The ln()
function will return NULL
if the argument is NULL
.
If the argument is zero, PostgreSQL will give an error: “Cannot take logarithm of zero”.
If the argument is negative, PostgreSQL will give an error: “Cannot take logarithm of negative number”.
PostgreSQL will give an error if you supply a parameter that is not a numeric type.
ln()
Examples
Here are a few examples of the ln()
function:
SELECT
ln(1) AS "ln(1)",
ln(2) AS "ln(-2)",
ln(3.3) AS "ln(3.3)";
ln(1) | ln(-2) | ln(3.3)
-------+--------------------+--------------------
0 | 0.6931471805599453 | 1.1939224684724346