PostgreSQL log() Function
The PostgreSQL log()
function returns the logarithm of the specified base of the number specified by the argument.
log()
Syntax
This is the syntax of the PostgreSQL log()
function:
log(base, numeric_value) -> double precision
log(10, numeric_value)
is equivalent to log10(numeric_value)
.
Parameters
base
-
Required. base.
numeric_value
-
Required. A number whose logarithm needs to be obtained.
Return value
The PostgreSQL log()
function returns the logarithm of the specified base of the number specified by the argument.
The log()
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.
log()
Examples
Here are a few examples of the log()
function:
SELECT
log(2, 3) AS "log(2, 3)",
log(10, 4) AS "log(10, 4)";
log(2, 3) | log(10, 4)
--------------------+--------------------
1.5849625007211562 | 0.6020599913279624
log(10, numeric_value)
is equivalent to log10(numeric_value)
. E.g:
SELECT
log(10, 4) AS "log(10, 4)",
log10(4) AS "log10(4)";
log(10, 4) | log10(4)
--------------------+--------------------
0.6020599913279624 | 0.6020599913279624