Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YC9yI-00045E-2e for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Jan 2015 16:42:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YC9yH-0002nX-Ir for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Jan 2015 16:42:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YC9yG-0002ll-4i for pgsql-bugs@postgresql.org; Fri, 16 Jan 2015 16:42:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YC9yC-0000va-JH for pgsql-bugs@postgresql.org; Fri, 16 Jan 2015 16:42:03 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t0GGfvDY028345; Fri, 16 Jan 2015 11:41:57 -0500 From: Tom Lane To: David G Johnston cc: pgsql-bugs@postgresql.org, damian@sepczuk.pl Subject: Re: BUG #12568: upper of int4range unexpected value In-reply-to: <1421424048619-5834296.post@n5.nabble.com> References: <20150116152713.2582.10294@wrigleys.postgresql.org> <1421424048619-5834296.post@n5.nabble.com> Comments: In-reply-to David G Johnston message dated "Fri, 16 Jan 2015 09:00:48 -0700" Date: Fri, 16 Jan 2015 11:41:57 -0500 Message-ID: <28344.1421426517@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org David G Johnston writes: > damian-2 wrote >> While technically 3 is an upper bound of the integer range [1,3) ∩ ℕ = {1, >> 2}, so are all natural numbers ≥ 2. I would expect the 'upper' function to >> return the supremum (least upper bound) of the range. >> In my opinion the result of upper('[1,2]'::int4range) = 3 is unexpected. > This is not a bug because the answer given, while not what you expect, is > not incorrect if you allow for the fact that the given bound can be either > inclusive or exclusive when dealing with a discrete range. > You already pointed out why the exclusive bound answer is chosen - it is a > natural consequence of the canonical form chosen for the type. Yeah. upper() is a simple representation-extraction function, so it's going to give the stored value which is 3. There might well be use-cases which would justify inventing infimum() and supremum() functions that behave as described, but we're not going to change the behavior of upper/lower at this point. The use-cases would have to be pretty darn convincing though, because AFAICS there's no way to provide these functions in a generic way: there'd need to be new per-range-type support functions to implement them. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs