Skip to content

Commit 9bd588f

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 27af8b9 commit 9bd588f

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
@@ -1739,13 +1739,23 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
17391739
which <parameter>operand</parameter> falls in a histogram
17401740
having <parameter>count</parameter> equal-width buckets spanning the
17411741
range <parameter>low</parameter> to <parameter>high</parameter>.
1742-
Returns <literal>0</literal>
1742+
The buckets have inclusive lower bounds and exclusive upper bounds.
1743+
Returns <literal>0</literal> for an input less
1744+
than <parameter>low</parameter>,
17431745
or <literal><parameter>count</parameter>+1</literal> for an input
1744-
outside that range.
1746+
greater than or equal to <parameter>high</parameter>.
1747+
If <parameter>low</parameter> &gt; <parameter>high</parameter>,
1748+
the behavior is mirror-reversed, with bucket <literal>1</literal>
1749+
now being the one just below <parameter>low</parameter>, and the
1750+
inclusive bounds now being on the upper side.
17451751
</para>
17461752
<para>
17471753
<literal>width_bucket(5.35, 0.024, 10.06, 5)</literal>
17481754
<returnvalue>3</returnvalue>
1755+
</para>
1756+
<para>
1757+
<literal>width_bucket(9, 10, 0, 10)</literal>
1758+
<returnvalue>2</returnvalue>
17491759
</para></entry>
17501760
</row>
17511761

@@ -1757,8 +1767,8 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
17571767
<para>
17581768
Returns the number of the bucket in
17591769
which <parameter>operand</parameter> falls given an array listing the
1760-
lower bounds of the buckets. Returns <literal>0</literal> for an
1761-
input less than the first lower
1770+
inclusive lower bounds of the buckets.
1771+
Returns <literal>0</literal> for an input less than the first lower
17621772
bound. <parameter>operand</parameter> and the array elements can be
17631773
of any type having standard comparison operators.
17641774
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
@@ -4010,8 +4010,8 @@ float84ge(PG_FUNCTION_ARGS)
40104010
* in the histogram. width_bucket() returns an integer indicating the
40114011
* bucket number that 'operand' belongs to in an equiwidth histogram
40124012
* with the specified characteristics. An operand smaller than the
4013-
* lower bound is assigned to bucket 0. An operand greater than the
4014-
* upper bound is assigned to an additional bucket (with number
4013+
* lower bound is assigned to bucket 0. An operand greater than or equal
4014+
* to the upper bound is assigned to an additional bucket (with number
40154015
* count+1). We don't allow "NaN" for any of the float8 inputs, and we
40164016
* don't allow either of the histogram bounds to be +/- infinity.
40174017
*/

src/backend/utils/adt/numeric.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,9 +1702,10 @@ generate_series_step_numeric(PG_FUNCTION_ARGS)
17021702
* in the histogram. width_bucket() returns an integer indicating the
17031703
* bucket number that 'operand' belongs to in an equiwidth histogram
17041704
* with the specified characteristics. An operand smaller than the
1705-
* lower bound is assigned to bucket 0. An operand greater than the
1706-
* upper bound is assigned to an additional bucket (with number
1707-
* count+1). We don't allow "NaN" for any of the numeric arguments.
1705+
* lower bound is assigned to bucket 0. An operand greater than or equal
1706+
* to the upper bound is assigned to an additional bucket (with number
1707+
* count+1). We don't allow "NaN" for any of the numeric inputs, and we
1708+
* don't allow either of the histogram bounds to be +/- infinity.
17081709
*/
17091710
Datum
17101711
width_bucket_numeric(PG_FUNCTION_ARGS)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy