A Quick Intro to PostgreSQL’s ERF() Function

In PostgreSQL, erf() is a mathematical function that provides the standard mathematical error function.

The erf() function was introduced in PostgreSQL 16, which was released on September 14th 2023.

Syntax

The syntax goes like this:

erf ( double precision )

Example

Here’s an example to demonstrate:

SELECT erf(1);

Result:

0.8427007929497148

Here’s an example that demonstrates the results from passing different values to the function:

\x
SELECT 
    erf(-3) AS "-3",
    erf(-2.5) AS "-2.5",
    erf(-2.5789) AS "-2.5789",
    erf(-0.01) AS "-0.01",
    erf(0) AS "0",
    erf(0.01) AS "0.01",
    erf(2.5789) AS "2.5789",
    erf(2.5) AS "2.5",
    erf(3) AS "3";

Result (using vertical output):

-3      | -0.9999779095030015
-2.5 | -0.999593047982555
-2.5789 | -0.9997347991172897
-0.01 | -0.011283415555849616
0 | 0
0.01 | 0.011283415555849616
2.5789 | 0.9997347991172897
2.5 | 0.999593047982555
3 | 0.9999779095030015

Passing a Null Value

Passing a null value results in null being returned:

SELECT erf(null);

Result:

null

Passing the Wrong Argument Type

Passing an argument of the wrong type results in an error:

SELECT erf('one');

Result:

ERROR:  invalid input syntax for type double precision: "one"
LINE 1: SELECT erf('one');
^