Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YC8wE-0001dI-Ue for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Jan 2015 15:35:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YC8wD-0007Nj-Ca for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Jan 2015 15:35:53 +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 1YC8og-0003YF-V2 for pgsql-bugs@postgresql.org; Fri, 16 Jan 2015 15:28:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YC8od-0007rj-My for pgsql-bugs@postgresql.org; Fri, 16 Jan 2015 15:28:05 +0000 MIME-Version: 1.0 Subject: BUG #12568: upper of int4range unexpected value To: pgsql-bugs@postgresql.org From: damian@sepczuk.pl Date: Fri, 16 Jan 2015 15:27:13 +0000 Message-ID: <20150116152713.2582.10294@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.2 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 The following bug has been logged on the website: Bug reference: 12568 Logged by: Damian Sepczuk Email address: damian@sepczuk.pl PostgreSQL version: 9.4.0 Operating system: Linux Mint 17.1 Cinnamon 64-bit 3.13.0-24-generic Description: 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. From pg documentation: upper(anyrange) | range's element type | upper bound of range | upper(numrange(1.1,2.2)) | 2.2 upper_inc(anyrange) | boolean | is the upper bound inclusive? | upper_inc(numrange(1.1,2.2)) | false and "The built-in range types int4range, int8range, and daterange all use a canonical form that includes the lower bound and excludes the upper bound; that is, [)." I understand, that the canonical form of the discrete range is [1,3) but, still, 3 is not the supremum of [1,3) in the discrete domain of int4 numbers. Supremum of [1,3) in int4 is 2. It seems that the upper and upper_inc functions don't take into account the fact the range is discrete. > SELECT version(); PostgreSQL 9.4.0 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit > SELECT x, lower(x), upper(x), lower_inc(x), upper_inc(x) FROM (SELECT '[1,2]'::int4range x) q; x | lower | upper | lower_inc | upper_inc -------+-------+-------+-----------+----------- [1,3) | 1 | 3 | t | f ^^^^^^^_____________^^^-----------> Unexpected! > SELECT x, lower(x), upper(x), lower_inc(x), upper_inc(x) FROM (SELECT '(1,2]'::int4range x) q; x | lower | upper | lower_inc | upper_inc -------+-------+-------+-----------+----------- [2,3) | 2 | 3 | t | f ^^^^^^^_____________^^^-----------> Unexpected! SELECT x, lower(x), upper(x), lower_inc(x), upper_inc(x) FROM (SELECT '(1,3)'::int4range x) q; x | lower | upper | lower_inc | upper_inc -------+-------+-------+-----------+----------- [2,3) | 2 | 3 | t | f ^^^^^^^_____________^^^-----------> Unexpected! SELECT x, lower(x), upper(x), lower_inc(x), upper_inc(x) FROM (SELECT '(1,2)'::int4range x) q; x | lower | upper | lower_inc | upper_inc -------+-------+-------+-----------+----------- empty | | | f | f > SELECT x, lower(x), upper(x), lower_inc(x), upper_inc(x) FROM (SELECT '[1,2]'::numrange x) q; x | lower | upper | lower_inc | upper_inc -------+-------+-------+-----------+----------- [1,2] | 1 | 2 | t | t > SELECT x, lower(x), upper(x), lower_inc(x), upper_inc(x) FROM (SELECT '[1,2)'::numrange x) q1; x | lower | upper | lower_inc | upper_inc -------+-------+-------+-----------+----------- [1,2) | 1 | 2 | t | f > SELECT x, lower(x), upper(x), lower_inc(x), upper_inc(x) FROM (SELECT '[1,3]'::numrange x) q1; x | lower | upper | lower_inc | upper_inc -------+-------+-------+-----------+----------- [1,3] | 1 | 3 | t | t -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs