8000 Doc: improve documentation about width_bucket(). · postgres/postgres@7a93bd5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a93bd5

Browse files
committed
Doc: improve documentation about width_bucket().
Specify whether the bucket bounds are inclusive or exclusive, and improve some other vague language. Explain the behavior that occurs when the "low" bound is greater than the "high" bound. Make width_bucket_numeric's comment more like that for width_bucket_float8, in particular noting that infinite bounds are rejected (since they became possible in v14). Reported-by: Ben Peachey Higdon <bpeacheyhigdon@gmail.com> Author: Robert Treat <rob@xzilla.net> Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/2BD74F86-5B89-4AC1-8F13-23CED3546AC1@gmail.com Backpatch-through: 13
1 parent 1e24ea1 commit 7a93bd5

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

doc/src/sgml/func.sgml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,13 +1774,23 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
17741774
which <parameter>operand</parameter> falls in a histogram
17751775
having <parameter>count</parameter> equal-width buckets spanning the
17761776
range <parameter>low</parameter> to <parameter>high</parameter>.
1777-
Returns <literal>0</literal>
1777+
The buckets have inclusive lower bounds and exclusive upper bounds.
1778+
Returns <literal>0</literal> for an input less
1779+
than <parameter>low</parameter>,
17781780
or <literal><parameter>count</parameter>+1</literal> for an input
1779-
outside that range.
1781+
greater than or equal to <parameter>high</parameter>.
1782+
If <parameter>low</parameter> &gt; <parameter>high</parameter>,
1783+
the behavior is mirror-reversed, with bucket <literal>1</literal>
1784+
now being the one just below <parameter>low</parameter>, and the
1785+
inclusive bounds now being on the upper side.
17801786
</para>
17811787
<para>
17821788
<literal>width_bucket(5.35, 0.024, 10.06, 5)</literal>
17831789
<returnvalue>3</returnvalue>
1790+
</para>
1791+
<para>
1792+
<literal>width_bucket(9, 10, 0, 10)</literal>
1793+
<returnvalue>2</returnvalue>
17841794
</para></entry>
17851795
</row>
17861796

@@ -1792,8 +1802,8 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
17921802
<para>
17931803
Returns the number of the bucket in
17941804
which <parameter>operand</parameter> falls given an array listing the
1795-
lower bounds of the buckets. Returns <literal>0</literal> for an
1796-
input less than the first lower
1805+
inclusive lower bounds of the buckets.
1806+
Returns <literal>0</literal> for an input less than the first lower
17971807
bound. <parameter>operand</parameter> and the array elements can be
17981808
of any type having standard comparison operators.
17991809
The <parameter>thresholds</parameter> array <emphasis>must be

src/backend/utils/adt/float.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4075,8 +4075,8 @@ float84ge(PG_FUNCTION_ARGS)
40754075
* in the histogram. width_bucket() returns an integer indicating the
40764076
* bucket number that 'operand' belongs to in an equiwidth histogram
40774077
* with the specified characteristics. An operand smaller than the
4078-
* lower bound is assigned to bucket 0. An operand greater than the
4079-
* upper bound is assigned to an additional bucket (with number
4078+
* lower bound is assigned to bucket 0. An operand greater than or equal
4079+
* to the upper bound is assigned to an additional bucket (with number
40804080
* count+1). We don't allow "NaN" for any of the float8 inputs, and we
40814081
* don't allow either of the histogram bounds to be +/- infinity.
40824082
*/

src/backend/utils/adt/numeric.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,9 +1835,10 @@ generate_series_step_numeric(PG_FUNCTION_ARGS)
18351835
* in the histogram. width_bucket() returns an integer indicating the
18361836
* bucket number that 'operand' belongs to in an equiwidth histogram
18371837
* with the specified characteristics. An operand smaller than the
1838-
* lower bound is assigned to bucket 0. An operand greater than the
1839-
* upper bound is assigned to an additional bucket (with number
1840-
* count+1). We don't allow "NaN" for any of the numeric arguments.
1838+
* lower bound is assigned to bucket 0. An operand greater than or equal
1839+
* to the upper bound is assigned to an additional bucket (with number
1840+
* count+1). We don't allow "NaN" for any of the numeric inputs, and we
1841+
* don't allow either of the histogram bounds to be +/- infinity.
18411842
*/
18421843
Datum
18431844
width_bucket_numeric(PG_FUNCTION_ARGS)

0 commit comments

Comments
 (0)
0