Re: Range Types and length function - Mailing list pgsql-hackers

From Jeff Davis
Subject Re: Range Types and length function
Date
Msg-id 1309108327.2443.191.camel@jdavis
Whole thread Raw
In response to Re: Range Types and length function  (Greg Stark <stark@mit.edu>)
List pgsql-hackers
On Sun, 2011-06-26 at 13:45 +0100, Greg Stark wrote:
> On Sun, Jun 26, 2011 at 8:18 AM, Jeff Davis <pgsql@j-davis.com> wrote:
> >  * it needs to know the result type of that function, which might not be
> > the subtype (for instance, for timestamp the difference type would be
> > interval)
> 
> What's the use case for the length() function? Is it for users to be
> able to display useful information about their ranges? Or is it for
> implementing things like GIST indexes?

Here I was talking about something for logical use, not GiST. It's
pretty common to want to know how long a range is.

> For the latter a length function that always returns a float might be
> more useful. Even if it isn't guaranteed to always be perfectly
> precise, that is if ranges of similar length sometimes returned
> identical values, at least it could be used for things like penalty().

I already have a function like that. It's actually a function that takes
the subtype and returns a float, and the GiST code does the subtraction.

But you're right, I could have a length function that always returns a
float instead, and that would do the job. Do you see an advantage?

If I had a length function that returned the subtype, I wouldn't need
that. Except for those pesky types like timestamp -- because then, even
if I had a length() function, I'd also need a total order on the
"interval" type.

Regards,Jeff Davis



pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Fwd: Keywords in pg_hba.conf should be field-specific
Next
From: "Kevin Grittner"
Date:
Subject: Re: Repeated PredicateLockRelation calls during seqscan