Skip to content

Commit 9575e54

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 fdd8269 commit 9575e54

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
@@ -1786,13 +1786,23 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in
17861786
which <parameter>operand</parameter> falls in a histogram
17871787
having <parameter>count</parameter> equal-width buckets spanning the
17881788
range <parameter>low</parameter> to <parameter>high</parameter>.
1789-
Returns <literal>0</literal>
1789+
The buckets have inclusive lower bounds and exclusive upper bounds.
1790+
Returns <literal>0</literal> for an input less
1791+
than <parameter>low</parameter>,
17901792
or <literal><parameter>count</parameter>+1</literal> for an input
1791-
outside that range.
1793+
greater than or equal to <parameter>high</parameter>.
1794+
If <parameter>low</parameter> &gt; <parameter>high</parameter>,
1795+
the behavior is mirror-reversed, with bucket <literal>1</literal>
1796+
now being the one just below <parameter>low</parameter>, and the
1797+
inclusive bounds now being on the upper side.
17921798
</para>
17931799
<para>
17941800
<literal>width_bucket(5.35, 0.024, 10.06, 5)</literal>
17951801
<returnvalue>3</returnvalue>
1802+
</para>
1803+
<para>
1804+
<literal>width_bucket(9, 10, 0, 10)</literal>
1805+
<returnvalue>2</returnvalue>
17961806
</para></entry>
17971807
</row>
17981808

@@ -1804,8 +1814,8 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in
18041814
<para>
18051815
Returns the number of the bucket in
18061816
which <parameter>operand</parameter> falls given an array listing the
1807-
lower bounds of the buckets. Returns <literal>0</literal> for an
1808-
input less than the first lower
1817+
inclusive lower bounds of the buckets.
1818+
Returns <literal>0</literal> for an input less than the first lower
18091819
bound. <parameter>operand</parameter> and the array elements can be
18101820
of any type having standard comparison operators.
18111821
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
@@ -3980,8 +3980,8 @@ float84ge(PG_FUNCTION_ARGS)
39803980
* in the histogram. width_bucket() returns an integer indicating the
39813981
* bucket number that 'operand' belongs to in an equiwidth histogram
39823982
* with the specified characteristics. An operand smaller than the
3983-
* lower bound is assigned to bucket 0. An operand greater than the
3984-
* upper bound is assigned to an additional bucket (with number
3983+
* lower bound is assigned to bucket 0. An operand greater than or equal
3984+
* to the upper bound is assigned to an additional bucket (with number
39853985
* count+1). We don't allow "NaN" for any of the float8 inputs, and we
39863986
* don't allow either of the histogram bounds to be +/- infinity.
39873987
*/

src/backend/utils/adt/numeric.c

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