Content-Length: 364928 | pFad | https://github.com/postgres/postgres/commit/#start-of-content

68570D25 Doc: improve documentation about width_bucket(). · postgres/postgres@ea06263 · GitHub
Skip to content

Commit ea06263

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 fa638ed commit ea06263

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
@@ -1824,13 +1824,23 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in
18241824
which <parameter>operand</parameter> falls in a histogram
18251825
having <parameter>count</parameter> equal-width buckets spanning the
18261826
range <parameter>low</parameter> to <parameter>high</parameter>.
1827-
Returns <literal>0</literal>
1827+
The buckets have inclusive lower bounds and exclusive upper bounds.
1828+
Returns <literal>0</literal> for an input less
1829+
than <parameter>low</parameter>,
18281830
or <literal><parameter>count</parameter>+1</literal> for an input
1829-
outside that range.
1831+
greater than or equal to <parameter>high</parameter>.
1832+
If <parameter>low</parameter> &gt; <parameter>high</parameter>,
1833+
the behavior is mirror-reversed, with bucket <literal>1</literal>
1834+
now being the one just below <parameter>low</parameter>, and the
1835+
inclusive bounds now being on the upper side.
18301836
</para>
18311837
<para>
18321838
<literal>width_bucket(5.35, 0.024, 10.06, 5)</literal>
18331839
<returnvalue>3</returnvalue>
1840+
</para>
1841+
<para>
1842+
<literal>width_bucket(9, 10, 0, 10)</literal>
1843+
<returnvalue>2</returnvalue>
18341844
</para></entry>
18351845
</row>
18361846

@@ -1842,8 +1852,8 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in
18421852
<para>
18431853
Returns the number of the bucket in
18441854
which <parameter>operand</parameter> falls given an array listing the
1845-
lower bounds of the buckets. Returns <literal>0</literal> for an
1846-
input less than the first lower
1855+
inclusive lower bounds of the buckets.
1856+
Returns <literal>0</literal> for an input less than the first lower
18471857
bound. <parameter>operand</parameter> and the array elements can be
18481858
of any type having standard comparison operators.
18491859
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
@@ -4065,8 +4065,8 @@ float84ge(PG_FUNCTION_ARGS)
40654065
* in the histogram. width_bucket() returns an integer indicating the
40664066
* bucket number that 'operand' belongs to in an equiwidth histogram
40674067
* with the specified characteristics. An operand smaller than the
4068-
* lower bound is assigned to bucket 0. An operand greater than the
4069-
* upper bound is assigned to an additional bucket (with number
4068+
* lower bound is assigned to bucket 0. An operand greater than or equal
4069+
* to the upper bound is assigned to an additional bucket (with number
40704070
* count+1). We don't allow "NaN" for any of the float8 inputs, and we
40714071
* don't allow either of the histogram bounds to be +/- infinity.
40724072
*/

src/backend/utils/adt/numeric.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,9 +1958,10 @@ generate_series_numeric_support(PG_FUNCTION_ARGS)
19581958
* in the histogram. width_bucket() returns an integer indicating the
19591959
* bucket number that 'operand' belongs to in an equiwidth histogram
19601960
* with the specified characteristics. An operand smaller than the
1961-
* lower bound is assigned to bucket 0. An operand greater than the
1962-
* upper bound is assigned to an additional bucket (with number
1963-
* count+1). We don't allow "NaN" for any of the numeric arguments.
1961+
* lower bound is assigned to bucket 0. An operand greater than or equal
1962+
* to the upper bound is assigned to an additional bucket (with number
1963+
* count+1). We don't allow "NaN" for any of the numeric inputs, and we
1964+
* don't allow either of the histogram bounds to be +/- infinity.
19641965
*/
19651966
Datum
19661967
width_bucket_numeric(PG_FUNCTION_ARGS)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/postgres/postgres/commit/#start-of-content

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy