Appearance
ROUND_VAR
Round a number (up or down) to the nearest integer. Optionally, specify the number of decimal places for the rounding. This function is equivalent to ROUND, except that it allows the second argument to be a column name or an expression, while ROUND
enforces the use of a constant.
ROUND_VAR(number [, places])
The return type of the ROUND_VAR
function is the DECIMAL
type of the first argument. For example:
ROUND_VAR(1.234, 1*2) returns 1.230
Examples
Determine the precision and scale of a given DECIMAL
value by using the integer values found in the seasonid
column of the season
table:
premdb=# select round_var(1.111567, seasonid), seasonid from season;
round_var | seasonid
-----------+----------
1.100000 | 1
1.110000 | 2
1.112000 | 3
1.111600 | 4
1.111570 | 5
1.111567 | 6
1.111567 | 7
1.111567 | 8
1.111567 | 9
...
(25 rows)
Note that the scale of the result is 6 decimal places, so the results for seasonid 6
and higher are the same.
Enabling ROUND_VAR Behavior for ROUND
If you commonly supply a variable number of decimal places to the ROUND
function, the configuration parameter enable_alternative_round
will instruct the query planner to automatically translate ROUND
to ROUND_VAR
without modifying the original SQL text.