From: David G Johnston <david.g.johnston@gmail.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #12568: upper of int4range unexpected value
Date: Fri, 16 Jan 2015 09:00:48 -0700 (MST)
Message-ID: <1421424048619-5834296.post@n5.nabble.com> (raw)
In-Reply-To: <20150116152713.2582.10294@wrigleys.postgresql.org>
References: <20150116152713.2582.10294@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
damian-2 wrote
> The following bug has been logged on the website:
>
> Bug reference: 12568
> Logged by: Damian Sepczuk
> Email address:
> damian@
> 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.
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.
So, at this point, you need to convince people why the inclusive bound is
the better one to supply. Your expectations, while valid, are likely
insufficient a reason to change. Range types have been in play since 9.2 so
it is still fairly early in their lifetime but it isn't like two years is
insufficient time to hear about differing opinions on the topic and this is
the first that I've noticed.
So, what practical benefits are there to reporting the inclusive maxima
instead of the exclusive one?
As a matter of consistency having continuous ranges - which have to report
inclusive maxima - and discrete ranges different on this point is
undesirable; but I have no practical reason what it even matters.
I'm personally sold on the formal theory argument and think that a design
that requires a separate function that returns whether a given bound is
inclusive or exclusive is a code smell...but my experience in this area is
quite limited and I don't know whether the current design was grounded in
formal mathematics like what you are proposing.
David J.
--
View this message in context: http://postgresql.nabble.com/BUG-12568-upper-of-int4range-unexpected-value-tp5834285p5834296.html
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: david.g.johnston@gmail.com
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>
* 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