A Quick Overview of the ERFC() Function in PostgreSQL

In PostgreSQL, erfc() is a mathematical function that provides the mathematical complementary error function, without loss of precision for large inputs. It returns 1 - erf(x).

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

Syntax

The syntax goes like this:

erfc ( double precision )

Example

Here’s an example to demonstrate:

SELECT erfc(1);

Result:

0.15729920705028516

As mentioned, the erfc() function returns 1 - erf(x):

SELECT 
    erfc(1) AS "erfc",
    1 - erf(1) AS "erf";

Result:

        erfc         |         erf         
---------------------+---------------------
0.15729920705028516 | 0.15729920705028522

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

\x
SELECT 
    erfc(1.75) AS "1.75",
    erfc(1.5) AS "1.5",
    erfc(1.25) AS "1.25",
    erfc(1) AS "1",
    erfc(0.75) AS "0.75",
    erfc(0.5) AS "0.5",
    erfc(0.25) AS "0.25";

Result (using vertical output):

1.75 | 0.013328328780817557
1.5 | 0.033894853524689274
1.25 | 0.07709987174354178
1 | 0.15729920705028516
0.75 | 0.28884436634648486
0.5 | 0.4795001221869535
0.25 | 0.7236736098317631

Passing a Null Value

Passing a null value results in null being returned:

SELECT erfc(null);

Result:

null

Passing the Wrong Argument Type

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

SELECT erfc('one');

Result:

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