Re: RangeType internal use - Mailing list pgsql-hackers

From Amit Langote
Subject Re: RangeType internal use
Date
Msg-id 54D80199.9060207@lab.ntt.co.jp
Whole thread Raw
In response to Re: RangeType internal use  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: RangeType internal use
List pgsql-hackers
On 07-02-2015 AM 12:10, Tom Lane wrote:
> Amit Langote <Langote_Amit_f8@lab.ntt.co.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




pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Add LINE: hint when schemaname.typename is a non-existent schema
Next
From: David Steele
Date:
Subject: Re: pgaudit - an auditing extension for PostgreSQL