{"id":9153,"date":"2020-07-04T09:56:52","date_gmt":"2020-07-03T23:56:52","guid":{"rendered":"https:\/\/database.guide\/?p=9153"},"modified":"2020-07-04T09:56:55","modified_gmt":"2020-07-03T23:56:55","slug":"how-the-scale-function-works-in-postgresql","status":"publish","type":"post","link":"https:\/\/database.guide\/how-the-scale-function-works-in-postgresql\/","title":{"rendered":"How the Scale() Function Works in PostgreSQL"},"content":{"rendered":"\n<p>In <a href=\"https:\/\/database.guide\/what-is-postgresql\/\" class=\"aioseop-link\">PostgreSQL<\/a>, the <code>scale()<\/code> function returns the scale of its argument.<\/p>\n\n\n\n<p>The scale is the number of decimal digits in the fractional part. <\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p>The syntax goes like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scale(numeric)<\/code><\/pre>\n\n\n\n<p>Where <code><em>numeric<\/em><\/code> is the number for which you want the scale returned.<\/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 scale(0.1234);<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">4<\/pre>\n\n\n\n<p>Here are some more.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n  scale(0) AS \"0\",\n  scale(0.1) AS \"0.1\",\n  scale(0.12) AS \"0.12\",\n  scale(0.123456789) AS \"0.123456789\";<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;0 | 0.1 | 0.12 | 0.123456789\n---+-----+------+-------------\n&nbsp;0 |&nbsp; &nbsp;1 |&nbsp; &nbsp; 2 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;9<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Negative Numbers<\/h2>\n\n\n\n<p>It works on negative numbers just the same.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n  scale(0) AS \"0\",\n  scale(-0.1) AS \"-0.1\",\n  scale(-0.12) AS \"-0.12\",\n  scale(-0.123456789) AS \"-0.123456789\";<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;0 | -0.1 | -0.12 | -0.123456789\n---+------+-------+--------------\n&nbsp;0 |&nbsp; &nbsp; 1 |&nbsp; &nbsp; &nbsp;2 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 9<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Expressions<\/h2>\n\n\n\n<p>You can also provide expressions, such as the following.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n  1.23 * 0.3 AS \"Result of expression\",\n  scale(1.23 * 0.3);<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;Result of expression | scale\n----------------------+-------\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.369 | 3<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In PostgreSQL, the scale() function returns the scale of its argument. The scale is the number of decimal digits in the fractional part.<\/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-9153","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\/9153","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=9153"}],"version-history":[{"count":2,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/9153\/revisions"}],"predecessor-version":[{"id":9155,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/9153\/revisions\/9155"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=9153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=9153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=9153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}