ln, log
On this page
Returns the natural logarithm or a logarithm with a specified base.
Syntax
ln(<expr>)
log(<expr> [, base => <base>])Arguments
| Argument | Type | Description |
|---|---|---|
<expr> | int, uint, or float | Input value. |
base | int | Optional constant; defaults to 10. Base for log. Use a positive base other than 1 for a real-valued logarithm. |
Returns
Returns float. Returns NULL if the input is NULL. For a valid base, zero input produces an infinity and negative input produces NaN.
Examples
Calculate logarithms of request counts before plotting services with very different traffic volumes:
VALUES ('checkout', 100), ('catalog', 1000), ('search', 10000)
SELECT $0 AS service, $1 AS events
SELECT
service, events,
round(log(events, base => 10) * 100.0) / 100.0 AS log10_events,
round(ln(events) * 1000.0) / 1000.0 AS ln_events+----------+--------+--------------+-----------+
| service | events | log10_events | ln_events |
+----------+--------+--------------+-----------+
| checkout | 100 | 2.0 | 4.605 |
| catalog | 1000 | 3.0 | 6.908 |
| search | 10000 | 4.0 | 9.21 |
+----------+--------+--------------+-----------+The base-10 logarithm increases by one for each tenfold increase in events. Results are rounded for display.