Re: Range types

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: tomas(at)tuxteam(dot)de
Cc: hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Range types
Date: 2009-12-16 19:45:54
Message-ID: 20091216194554.GI4156@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

tomas(at)tuxteam(dot)de wrote:

> (and as Andrew Dunstan pointed out off-list: I was wrong with my bold
> assertion that one can squeeze infinitely many (arbitrary length)
> strings between two given. This is not always the case).

Of course you can do that if you assume lexicographical order, or any
other arbitrary order. The interesting point is whether there exists
some ordering on which this does not happen. And in fact there is:
order strings by length first, and then lexicographically. If you do
this then you have next() and prev() for any given string. If you use
ASCII only, you have a.next = b, and so on.

There is the argument that some languages do not sort lexicographically
but this is also besides the point -- you only need to find *some* way
to sort the characters in the alphabet. If you dictate that in your
ordering "á" comes before "à" and both after "a", and all of them before
b, then you know that a.next = á and á.next = à and à.next = b. (Note
that I have also dictated that there is no other character that sorts
after a and before b, which is perfectly possible because the alphabet
is fixed for any given language. You could use the complete list of
characters coded in a given set of Unicode planes, or even extant all
planes, to obtain the same result).

Defining strings with this ordering means you can have some useful
ranges like [a-z], but then you cannot meaningfully use ranges for
things like [aardvark - zulu] --- note that in this particular example,
the order is reversed, because zulu comes before aardvark which is
probably not what you want. zzz.next = aaaa

In short, I think that while it is possible to define ranges of strings,
it is not as useful as one would like.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David E. Wheeler 2009-12-16 20:05:10 Does "verbose" Need to be Reserved?
Previous Message Magnus Hagander 2009-12-16 19:39:14 Re: PATCH: Spurious "22" in hstore.sgml