PostgreSQL SCALE() Function
The PostgreSQL SCALE() function returns the scale of the argument (the number of decimal digits in the fractional part).
Syntax
SCALE(number)
Parameters
number |
Required. Specify the number. |
Return Value
Returns the scale of the argument.
Example 1:
The example below shows the usage of SCALE() function.
SELECT SCALE(0.12345); Result: 5 SELECT SCALE(1.2345); Result: 4 SELECT SCALE(12.345); Result: 3 SELECT SCALE(123.45); Result: 2 SELECT SCALE(1234.5); Result: 1 SELECT SCALE(12345); Result: 0 SELECT SCALE('123.45'); Result: 2
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | 1.56 |
Data 2 | 1.7 |
Data 3 | 1.89 |
Data 4 | 1.634 |
Data 5 | 1.678 |
The statement given below can be used to calculate the scale of column x values.
SELECT *, SCALE(x) AS SCALE_Value FROM Sample;
This will produce the result as shown below:
Data | x | SCALE_Value |
---|---|---|
Data 1 | 1.56 | 2 |
Data 2 | 1.7 | 1 |
Data 3 | 1.89 | 2 |
Data 4 | 1.634 | 3 |
Data 5 | 1.678 | 3 |
❮ PostgreSQL Functions