Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEBou-0001ci-93 for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Jan 2023 16:13:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pEBor-0004a6-Ej for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Jan 2023 16:13:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEBoq-0004Zw-Td for pgsql-bugs@lists.postgresql.org; Sat, 07 Jan 2023 16:13:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEBoi-0006LO-5x for pgsql-bugs@lists.postgresql.org; Sat, 07 Jan 2023 16:13:13 +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 307GD6sJ3452153; Sat, 7 Jan 2023 11:13:06 -0500 From: Tom Lane To: Dino Maric cc: pgsql-bugs@lists.postgresql.org Subject: Re: Confusion about the range types In-reply-to: References: Comments: In-reply-to Dino Maric message dated "Sat, 07 Jan 2023 16:17:19 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3452151.1673107986.1@sss.pgh.pa.us> Date: Sat, 07 Jan 2023 11:13:06 -0500 Message-ID: <3452152.1673107986@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dino Maric writes: > When I insert range like this: > INSERT INTO public.tests > VALUES (int4range(7,8,'[]')) > After when querying table my return value for this column is not [7,8] > but it is [7,9). > I found this behaviour confusing, because I want to insert 7-8 ranges > (including upper value) and then present that range to a user. This is the effect of canonicalization, as explained here: https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-DISCRETE If you don't like it you can make a range type with a different canonicalization function, or no such function, but that might have odd effects on the behavior of range comparison operators. regards, tom lane