agora inbox for pgsql-docs@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Treat <rob@xzilla.net>
Cc: Ben Peachey Higdon <bpeacheyhigdon@gmail.com>
Cc: pgsql-docs@lists.postgresql.org
Subject: Re: Document if width_bucket's low and high are inclusive/exclusive
Date: Fri, 20 Jun 2025 17:19:21 -0400
Message-ID: <2525554.1750454361@sss.pgh.pa.us> (raw)
In-Reply-To: <1391433.1750345913@sss.pgh.pa.us>
References: <2BD74F86-5B89-4AC1-8F13-23CED3546AC1@gmail.com>
	<CABV9wwPh9+JAYBudAhTY8yPj5VJACA_FpHfEAaHMX1s4z05VkQ@mail.gmail.com>
	<1167135.1750277532@sss.pgh.pa.us>
	<CAJSLCQ2aNwXntHfFZdLnrAqrhPUbm7YqytobFOid5mX3VU-C5g@mail.gmail.com>
	<1391433.1750345913@sss.pgh.pa.us>

I wrote:
> Another thing I just remembered (think I knew it once) is the
> behavior of the first form when low > high.  It's not an error!

So concretely, how about the attached?  In addition to what we
mentioned so far, I made the sentence about out-of-range cases
more explicit.

			regards, tom lane

Attachments:

  [text/x-diff] v2-0001-Document-width_bucket-range-as-inclusive-exclusiv.patch (2.1K, ../2525554.1750454361@sss.pgh.pa.us/2-v2-0001-Document-width_bucket-range-as-inclusive-exclusiv.patch)
  download | inline diff:
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 8d7d9a2f3e8..11676b63c82 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1824,13 +1824,24 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in
         which <parameter>operand</parameter> falls in a histogram
         having <parameter>count</parameter> equal-width buckets spanning the
         range <parameter>low</parameter> to <parameter>high</parameter>.
-        Returns <literal>0</literal>
+        The buckets have inclusive lower bounds, and therefore exclusive
+        upper bounds.
+        Returns <literal>0</literal> for an input less
+        than <parameter>low</parameter>,
         or <literal><parameter>count</parameter>+1</literal> for an input
-        outside that range.
+        greater than or equal to <parameter>high</parameter>.
+        If <parameter>low</parameter> &gt; <parameter>high</parameter>,
+        the behavior is mirror-reversed, with bucket <literal>1</literal>
+        now being the one just below <parameter>low</parameter>, and the
+        inclusive bounds now being on the upper side.
        </para>
        <para>
         <literal>width_bucket(5.35, 0.024, 10.06, 5)</literal>
         <returnvalue>3</returnvalue>
+       </para>
+       <para>
+        <literal>width_bucket(9, 10, 0, 10)</literal>
+        <returnvalue>2</returnvalue>
        </para></entry>
       </row>
 
@@ -1842,8 +1853,8 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in
        <para>
         Returns the number of the bucket in
         which <parameter>operand</parameter> falls given an array listing the
-        lower bounds of the buckets.  Returns <literal>0</literal> for an
-        input less than the first lower
+        inclusive lower bounds of the buckets.
+        Returns <literal>0</literal> for an input less than the first lower
         bound.  <parameter>operand</parameter> and the array elements can be
         of any type having standard comparison operators.
         The <parameter>thresholds</parameter> array <emphasis>must be

view thread (10+ messages)  latest in thread

Message-ID: <2525554.1750454361@sss.pgh.pa.us>
Permalink:  ../2525554.1750454361@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2525554.1750454361@sss.pgh.pa.us

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rob@xzilla.net, bpeacheyhigdon@gmail.com, pgsql-docs@lists.postgresql.org
  Subject: Re: Document if width_bucket's low and high are inclusive/exclusive
  In-Reply-To: <2525554.1750454361@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox