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 1qnmSZ-00BxwH-5k for pgsql-docs@arkaria.postgresql.org; Tue, 03 Oct 2023 20:57:39 +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 1qnmSX-008kPJ-AP for pgsql-docs@arkaria.postgresql.org; Tue, 03 Oct 2023 20:57:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnmSX-008kPB-1I for pgsql-docs@lists.postgresql.org; Tue, 03 Oct 2023 20:57:37 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnmSU-0082Xp-Nj for pgsql-docs@lists.postgresql.org; Tue, 03 Oct 2023 20:57:36 +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 393KvWu32451989; Tue, 3 Oct 2023 16:57:33 -0400 From: Tom Lane To: themyth.cs@gmail.com cc: pgsql-docs@lists.postgresql.org Subject: Re: INT4RANGE Upper bound always includes a higher number In-reply-to: <169635964997.3727336.14464470245213767871@wrigleys.postgresql.org> References: <169635964997.3727336.14464470245213767871@wrigleys.postgresql.org> Comments: In-reply-to PG Doc comments form message dated "Tue, 03 Oct 2023 19:00:49 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2451987.1696366652.1@sss.pgh.pa.us> Date: Tue, 03 Oct 2023 16:57:32 -0400 Message-ID: <2451988.1696366652@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Doc comments form writes: > According to your example (copied from your docs): > -- includes 3, does not include 7, and does include all points in between > SELECT '[3,7)'::int4range; > But this is not true, it shows 3 and 7 What's not true about it? postgres=# SELECT 3 <@ '[3,7)'::int4range; ?column? ---------- t (1 row) postgres=# SELECT 6 <@ '[3,7)'::int4range; ?column? ---------- t (1 row) postgres=# SELECT 7 <@ '[3,7)'::int4range; ?column? ---------- f (1 row) 7 is not a member of that range, only an endpoint. > And if i do: > SELECT '(3,7]'::INT4RANGE; > It shows: > [4,8) > (1 row) This is a consequence of canonicalization. There are four different ways to write the same integer range: [3,6] [3,7) (2,6] (2,7) All of these include 3,4,5,6 and no other integer. INT4RANGE has a canonicalize function that converts ranges into the "[m,n)" form so that ranges that are functionally identical look identical. If you don't like that, you can make a user-defined range type with a different canonicalize function, or none at all. See https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-DISCRETE regards, tom lane