Re: Range Types and length function

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Range Types and length function
Date: 2011-06-26 17:12:07
Message-ID: 1309108327.2443.191.camel@jdavis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)j-davis(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2011-06-26 20:02:12 Re: Repeated PredicateLockRelation calls during seqscan
Previous Message Pavel Stehule 2011-06-26 17:10:13 Re: Fwd: Keywords in pg_hba.conf should be field-specific