{"id":36879,"date":"2024-07-29T11:34:56","date_gmt":"2024-07-29T01:34:56","guid":{"rendered":"https:\/\/database.guide\/?p=36879"},"modified":"2024-07-29T11:34:58","modified_gmt":"2024-07-29T01:34:58","slug":"a-quick-intro-to-postgresqls-erf-function","status":"publish","type":"post","link":"https:\/\/database.guide\/a-quick-intro-to-postgresqls-erf-function\/","title":{"rendered":"A Quick Intro to PostgreSQL&#8217;s ERF() Function"},"content":{"rendered":"\n<p class=\"\">In PostgreSQL, <code>erf()<\/code> is a mathematical function that provides the standard mathematical <a href=\"https:\/\/mathworld.wolfram.com\/Erf.html\" data-type=\"link\" data-id=\"https:\/\/mathworld.wolfram.com\/Erf.html\" target=\"_blank\" rel=\"noreferrer noopener\">error function<\/a>.<\/p>\n\n\n\n<p class=\"\">The <code>erf()<\/code> function was introduced in PostgreSQL 16, which was released on September 14th 2023.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p class=\"\">The syntax goes like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>erf ( double precision )<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p class=\"\">Here&#8217;s an example to demonstrate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT erf(1);<\/code><\/pre>\n\n\n\n<p class=\"\">Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0.8427007929497148<\/pre>\n\n\n\n<p class=\"\">Here&#8217;s an example that demonstrates the results from passing different values to the function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\\x\nSELECT \n    erf(-3) AS \"-3\",\n    erf(-2.5) AS \"-2.5\",\n    erf(-2.5789) AS \"-2.5789\",\n    erf(-0.01) AS \"-0.01\",\n    erf(0) AS \"0\",\n    erf(0.01) AS \"0.01\",\n    erf(2.5789) AS \"2.5789\",\n    erf(2.5) AS \"2.5\",\n    erf(3) AS \"3\";<\/code><\/pre>\n\n\n\n<p class=\"\">Result (using vertical output):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">-3      | -0.9999779095030015<br>-2.5    | -0.999593047982555<br>-2.5789 | -0.9997347991172897<br>-0.01   | -0.011283415555849616<br>0       | 0<br>0.01    | 0.011283415555849616<br>2.5789  | 0.9997347991172897<br>2.5     | 0.999593047982555<br>3       | 0.9999779095030015<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Passing a Null Value<\/h2>\n\n\n\n<p class=\"\">Passing a null value results in <code>null<\/code> being returned:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT erf(null);<\/code><\/pre>\n\n\n\n<p class=\"\">Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">null<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Passing the Wrong Argument Type<\/h2>\n\n\n\n<p class=\"\">Passing an argument of the wrong type results in an error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT erf('one');<\/code><\/pre>\n\n\n\n<p class=\"\">Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ERROR:  invalid input syntax for type double precision: \"one\"<br>LINE 1: SELECT erf('one');<br>                   ^<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[93,70,20],"class_list":["post-36879","post","type-post","status-publish","format-standard","hentry","category-postgresql","tag-functions","tag-mathematical-functions","tag-what-is"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/36879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=36879"}],"version-history":[{"count":5,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/36879\/revisions"}],"predecessor-version":[{"id":36885,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/36879\/revisions\/36885"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=36879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=36879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=36879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}