Re: RangeType internal use

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: RangeType internal use
Date: 2015-02-09 00:38:49
Message-ID: 54D80199.9060207@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 07-02-2015 AM 12:10, Tom Lane wrote:
> Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp> writes:
>> I wonder why I cannot find a way to get a range type for a given (sub-)
>> type. I would like to build a RangeType from Datum's of lower and upper
>> bounds. Much like how construct_array() builds an ArrayType from a Datum
>> array of elements given elements' type info.
>
>> Is there some way I do not seem to know? If not, would it be worthwhile
>> to make something like construct_range() that returns a RangeType given
>> Datum's of lower and upper bounds and subtype info?
>
> There is no good reason to assume that a range type exists at all, much
> less that it is unique for a subtype. (Read the CREATE TYPE documentation
> if you're unclear as to why not.) You have not said what you're trying to
> accomplish, but this seems like a dead end.
>

We do have a number of built-in range types which we can safely assume
to exist with whatever default behavior they are hard-coded with (which
I guess are not 'ALTER TYPE'-able). Those existing range types cover a
useful set of sub-types which are probably also the potential candidates
to be used for range partitioning.

Now, one may define a new range type for a given sub-type with a
different subopclass, subcollation, subcanonical or subdiff, which is
perhaps the problem you are mentioning. Perhaps not very appropriate a
solution, but how about a rngtypisdefault (for a sub-type) flag?

Sorry I didn't mention before about an idea I am trying to implement
with this - it is to serialize range partition bounds as a range type
value per partition key column. The serialized representation of a range
partition bound for a partition then effectively becomes an anyarray of
anyrange:

+ rangebounds = construct_array(datum,
+ partnatts,
+ ANYRANGEOID,
+ -1,
+ false,
+ 'd');

each element of the passed datum array is a range type value of the
corresponding subtype.

Now, range types may not yet be ripe for internal use but the above idea
kind of works modulo the absence of infrastructure I was asking for in OP.

Am I still missing something?

Thanks,
Amit

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2015-02-09 01:02:41 Re: pgaudit - an auditing extension for PostgreSQL
Previous Message Tom Lane 2015-02-09 00:23:18 Re: Add LINE: hint when schemaname.typename is a non-existent schema