mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
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
This commit is contained in:
@ -51,14 +51,21 @@
|
||||
In general, enclose the value in single quotes, doubling any single
|
||||
quotes within the value. Quotes can usually be omitted if the value
|
||||
is a simple number or identifier, however.
|
||||
(Values that match a SQL keyword require quoting in some contexts.)
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
<emphasis>Numeric (integer and floating point):</emphasis>
|
||||
A decimal point is permitted only for floating-point parameters.
|
||||
Do not use thousands separators. Quotes are not required.
|
||||
Numeric parameters can be specified in the customary integer and
|
||||
floating-point formats; fractional values are rounded to the nearest
|
||||
integer if the parameter is of integer type. Integer parameters
|
||||
additionally accept hexadecimal input (beginning
|
||||
with <literal>0x</literal>) and octal input (beginning
|
||||
with <literal>0</literal>), but these formats cannot have a fraction.
|
||||
Do not use thousands separators.
|
||||
Quotes are not required, except for hexadecimal input.
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
@ -99,6 +106,13 @@
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
If a fractional value is specified with a unit, it will be rounded
|
||||
to a multiple of the next smaller unit if there is one.
|
||||
For example, <literal>30.1 GB</literal> will be converted
|
||||
to <literal>30822 MB</literal> not <literal>32319628902 B</literal>.
|
||||
If the parameter is of integer type, a final rounding to integer
|
||||
occurs after any units conversion.
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
|
Reference in New Issue
Block a user