Allow fractional input values for integer GUCs, and improve rounding logic.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 11 Mar 2019 23:13:46 +0000 (19:13 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 11 Mar 2019 23:13:55 +0000 (19:13 -0400)
commit1a83a80a2fe5b559f85ed4830acb92d5124b7a9a
treed6dd443a20eef9147572f430a707308f8326eab7
parentfe0b2c12c992fa44ca0448bde9099957306c843f
Allow fractional input values for integer GUCs, and improve rounding logic.

Historically guc.c has just refused examples like set work_mem = '30.1GB',
but it seems more useful for it to take that and round off the value to
some reasonable approximation of what the user said.  Just rounding to
the parameter's native unit would work, but it would lead to rather
silly-looking settings, such as 31562138kB for this example.  Instead
let's round to the nearest multiple of the next smaller unit (if any),
producing 30822MB.

Also, do the units conversion math in floating point and round to integer
(if needed) only at the end.  This produces saner results for inputs that
aren't exact multiples of the parameter's native unit, and removes another
difference in the behavior for integer vs. float parameters.

In passing, document the ability to use hex or octal input where it
ought to be documented.

Discussion: https://postgr.es/m/1798.1552165479@sss.pgh.pa.us
doc/src/sgml/config.sgml
src/backend/utils/misc/guc.c
src/test/regress/expected/reloptions.out
src/test/regress/sql/reloptions.sql