{"id":9191,"date":"2020-06-19T10:55:24","date_gmt":"2020-06-19T00:55:24","guid":{"rendered":"https:\/\/database.guide\/?p=9191"},"modified":"2020-06-19T10:56:07","modified_gmt":"2020-06-19T00:56:07","slug":"how-the-exp-function-works-in-postgresql","status":"publish","type":"post","link":"https:\/\/database.guide\/how-the-exp-function-works-in-postgresql\/","title":{"rendered":"How the Exp() Function Works in PostgreSQL"},"content":{"rendered":"\n<p>In <a href=\"https:\/\/database.guide\/what-is-postgresql\/\" class=\"aioseop-link\">PostgreSQL<\/a>, <code>exp()<\/code> is a mathematical function that returns the exponential value of its argument.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p>The official syntax goes like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exp(dp or numeric)<\/code><\/pre>\n\n\n\n<p>Where <code>dp<\/code> is a double precision value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p>Here&#8217;s an example of how it works.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT exp(1);<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">2.718281828459045<\/pre>\n\n\n\n<p>And here&#8217;s the result if we increase the argument to 2.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT exp(2);<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">7.38905609893065<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Fractions<\/h2>\n\n\n\n<p>This example includes a fractional part in the argument.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT exp(1.1);<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">3.0041660239464331<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Expressions<\/h2>\n\n\n\n<p>You can include expressions, such as this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT exp(3 * 4);<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">162754.79141900392<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exp() vs Ln()<\/h2>\n\n\n\n<p>The <code><a href=\"https:\/\/database.guide\/how-the-ln-function-works-in-postgresql\/\" class=\"aioseop-link\">ln()<\/a><\/code> function returns the natural logarithm, which is the inverse of <code>exp()<\/code>.<\/p>\n\n\n\n<p>The natural logarithm of the exponential of a number is the number itself. <\/p>\n\n\n\n<p>And the exponential of the natural logarithm of a number is the number itself.<\/p>\n\n\n\n<p>We can verify this as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n  ln(exp(1)),\n  exp(ln(1));<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;ln | exp\n----+-----\n&nbsp; 1 | 1<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In PostgreSQL, exp() is a mathematical function that returns the exponential value of its argument.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[93,70,20],"class_list":["post-9191","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\/9191","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=9191"}],"version-history":[{"count":5,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/9191\/revisions"}],"predecessor-version":[{"id":9204,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/9191\/revisions\/9204"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=9191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=9191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=9191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}