width_bucket()
Returns the number of the bucket in which operand falls in a histogram having count equal-width buckets spanning the range low to high. The buckets have inclusive lower bounds and exclusive upper bounds. Returns 0 for an input less than low, or count+1 for an input 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.
Signature
width_bucket ( operand numeric, low numeric, high numeric, count integer ) → integer
width_bucket ( operand double precision, low double precision, high double precision, count integer ) → integer
width_bucket ( operand anycompatible, thresholds anycompatiblearray ) → integerExamples
SELECT width_bucket(5.35, 0.024, 10.06, 5);3SELECT width_bucket(9, 10, 0, 10);2SELECT width_bucket(now(), array['yesterday', 'today', 'tomorrow']::timestamptz[]);2Run against PostgreSQL 18.6 on 2026-09-13. This is the output we got, not the documentation’s.
Want to run this against your own PostgreSQL server from an iPhone, iPad or Mac? These are ours — every connection goes straight from the device to your database, with no account and no server of ours in between.
Signature and description adapted from the PostgreSQL manual, used under the PostgreSQL License. PostgreSQL is a registered trademark of the PostgreSQL Community Association of Canada. This page is not affiliated with the PostgreSQL Global Development Group.