Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uSj8x-00CHov-CD for pgsql-docs@arkaria.postgresql.org; Fri, 20 Jun 2025 21:19:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uSj8v-004Pxe-Da for pgsql-docs@arkaria.postgresql.org; Fri, 20 Jun 2025 21:19:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uSj8v-004PxW-5O for pgsql-docs@lists.postgresql.org; Fri, 20 Jun 2025 21:19:25 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uSj8t-003DHW-1g for pgsql-docs@lists.postgresql.org; Fri, 20 Jun 2025 21:19:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 55KLJLii2525555; Fri, 20 Jun 2025 17:19:21 -0400 From: Tom Lane To: Robert Treat cc: Ben Peachey Higdon , pgsql-docs@lists.postgresql.org Subject: Re: Document if width_bucket's low and high are inclusive/exclusive In-reply-to: <1391433.1750345913@sss.pgh.pa.us> References: <2BD74F86-5B89-4AC1-8F13-23CED3546AC1@gmail.com> <1167135.1750277532@sss.pgh.pa.us> <1391433.1750345913@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 19 Jun 2025 11:11:53 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2525476.1750454297.0@sss.pgh.pa.us> Date: Fri, 20 Jun 2025 17:19:21 -0400 Message-ID: <2525554.1750454361@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2525476.1750454297.1@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 ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name*0="v2-0001-Document-width_bucket-range-as-inclusive-exclusiv.p"; name*1="atch"; charset="us-ascii" Content-ID: <2525476.1750454297.2@sss.pgh.pa.us> Content-Description: v2-0001-Document-width_bucket-range-as-inclusive-exclusiv.patch Content-Transfer-Encoding: quoted-printable 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 operand falls in a histogram having count equal-width buckets spanning = the range low to high. - Returns 0 + The buckets have inclusive lower bounds, and therefore exclusive + upper bounds. + Returns 0 for an input less + than low, or count+1 for an input - outside that range. + greater than or equal to high. + If low > high, + the behavior is mirror-reversed, with bucket 1 + now being the one just below low, and the + inclusive bounds now being on the upper side. width_bucket(5.35, 0.024, 10.06, 5) 3 + + + width_bucket(9, 10, 0, 10) + 2 = @@ -1842,8 +1853,8 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- = detect at least one null in Returns the number of the bucket in which operand falls given an array listing= the - lower bounds of the buckets. Returns 0 for an - input less than the first lower + inclusive lower bounds of the buckets. + Returns 0 for an input less than the first low= er bound. operand and the array elements can= be of any type having standard comparison operators. The thresholds array must be ------- =_aaaaaaaaaa0--