PostgreSQL min_scale() Function
The PostgreSQL min_scale()
function returns the minimum precision (number of decimal places) required to represent a given number accurately.
min_scale()
Syntax
This is the syntax of the PostgreSQL min_scale()
function:
min_scale(numeric_value) -> integer
Parameters
numeric_value
-
Required. a number.
Return value
The PostgreSQL min_scale()
function returns the minimum precision (number of decimal places) required to represent the given number exactly, that is, the number of the fractional part with removing all trailing 0.
If the argument is an integer, the min_scale()
function will return 0
.
If the argument has fractional part, the min_scale()
function returns the number of the fractional part with removing the trailing 0.
The min_scale()
function will return NULL
if the argument is NULL
.
PostgreSQL will give an error if you supply a parameter that is not a numeric type.
min_scale()
Examples
Here are a few examples of the min_scale()
function:
If the argument is an integer, the min_scale()
function will return 0
.
SELECT
min_scale(1) AS "min_scale(1)",
min_scale(2) AS "min_scale(2)",
min_scale(123) AS "min_scale(123)";
min_scale(1) | min_scale(2) | min_scale(123)
--------------+--------------+----------------
0 | 0 | 0
If the argument has fractional part, the min_scale()
function returns the number of the fractional part with removing the trailing 0.
SELECT min_scale(1.23000) AS "min_scale(1.23000)";
min_scale(1.23000)
--------------------
2
Here, the fractional part of 1.23000
is 23000
. The 3 zeroes in the end are useless, so min_scale(1.23000)
returned 2.