pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G Johnston <david.g.johnston@gmail.com>
Cc: pgsql-bugs@postgresql.org
Cc: damian@sepczuk.pl
Subject: Re: BUG #12568: upper of int4range unexpected value
Date: Fri, 16 Jan 2015 11:41:57 -0500
Message-ID: <28344.1421426517@sss.pgh.pa.us> (raw)
In-Reply-To: <1421424048619-5834296.post@n5.nabble.com>
References: <20150116152713.2582.10294@wrigleys.postgresql.org>
	<1421424048619-5834296.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

David G Johnston <david.g.johnston@gmail.com> 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



view thread (3+ messages)

Message-ID: <28344.1421426517@sss.pgh.pa.us>
Permalink:  ../28344.1421426517@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/28344.1421426517@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, damian@sepczuk.pl
  Subject: Re: BUG #12568: upper of int4range unexpected value
  In-Reply-To: <28344.1421426517@sss.pgh.pa.us>
  References: <20150116152713.2582.10294@wrigleys.postgresql.org> <1421424048619-5834296.post@n5.nabble.com> <28344.1421426517@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox