Re: Range Types, constructors, and the type system

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: Florian Pflug <fgp(at)phlo(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Range Types, constructors, and the type system
Date: 2011-07-05 17:06:22
Message-ID: CA+TgmoYwO5oZm62i__ChkdA0CCYiHcwm9cBDDgZ9jeQYkbuheQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jul 5, 2011 at 12:54 PM, Jeff Davis <pgsql(at)j-davis(dot)com> wrote:
> On Tue, 2011-07-05 at 11:26 -0400, Robert Haas wrote:
>> How about the idea of creating a family of four constructor functions
>> for each new range type?  The functions would be named after the range
>> type, with "_cc", "_co", "_oc", and "_oo" appended.  So, then, instead
>> of writing:
>>
>> RANGE(1,8,'c','o')::int8range
>
> It would be something like: range_co(1,8)::int8range
>
> (just so we're comparing apples to apples)
>
> The intermediate type proposal doesn't require that we move the "c" and
> "o" into the parameter list.

Well, you have to specify the bounds somewhere...

>> int8range_co(1,8)
>>
>> ...which is both more compact and less ugly, IMHO, and seems to
>> circumvent all the type system problems as well.
>
> I brought that up before:
> http://archives.postgresql.org/pgsql-hackers/2011-06/msg02046.php
>
> It certainly circumvents the polymorphic type problems, but the problem
> is that it adds up to quite a few permutations. Not only are there
> cc/co/oc/oo, but there are also variations for infinite bounds and empty
> ranges. So I think we're talking 10+ functions per range type rather
> than 4.

OK, so let's pass the information on the bounds as a separate
argument. Like this:

int8range(1,8,'co')

Then you can instead pass 'o' for open or 'i' for infinity (passing
NULL for the corresponding argument position in that case). The third
argument can be optional and default to 'cc'.

For empty ranges I doubt we need a separate constructor function;
presumably the representation of an empty range is some fixed string
and users can just write 'empty'::int8range or similar.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2011-07-05 17:06:41 SSI 2PC coverage
Previous Message Kevin Grittner 2011-07-05 17:03:52 SSI atomic commit