PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References
PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References

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:

Datax
Data 11.56
Data 21.7
Data 31.89
Data 41.634
Data 51.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:

DataxSCALE_Value
Data 11.562
Data 21.71
Data 31.892
Data 41.6343
Data 51.6783

❮ PostgreSQL Functions