How the Exp() Function Works in PostgreSQL

In PostgreSQL, exp() is a mathematical function that returns the exponential value of its argument.

Syntax

The official syntax goes like this:

exp(dp or numeric)

Where dp is a double precision value.

Example

Here’s an example of how it works.

SELECT exp(1);

Result:

2.718281828459045

And here’s the result if we increase the argument to 2.

SELECT exp(2);

Result:

7.38905609893065

Fractions

This example includes a fractional part in the argument.

SELECT exp(1.1);

Result:

3.0041660239464331

Expressions

You can include expressions, such as this.

SELECT exp(3 * 4);

Result:

162754.79141900392

Exp() vs Ln()

The ln() function returns the natural logarithm, which is the inverse of exp().

The natural logarithm of the exponential of a number is the number itself.

And the exponential of the natural logarithm of a number is the number itself.

We can verify this as follows.

SELECT 
  ln(exp(1)),
  exp(ln(1));

Result:

 ln | exp
----+-----
  1 | 1