Re: interval / interval -> double operator

From: "Andrew Hammond" <andrew(dot)george(dot)hammond(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: interval / interval -> double operator
Date: 2007-05-18 00:15:56
Message-ID: 5a0a9d6f0705171715m51b10bd0jf5086ca0567ba87f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 5/17/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Andrew Hammond <andrew(dot)george(dot)hammond(at)gmail(dot)com> writes:
> > Yet another potential addition to the family of operators. Some guy
> > was asking for it on IRC so...
>
> > CREATE OR REPLACE FUNCTION interval_over_interval(interval, interval)
> > RETURNS float STRICT IMMUTABLE LANGUAGE sql AS $$
> > SELECT extract(epoch from $1)::float / extract(epoch from $2);
> > $$;
>
> What are the grounds for defining it that way rather than some other
> way?
>

The only alternative that came to mind when I wrote it was using a numeric
instead of float. I couldn't see why a numeric with some arbitrary precision
/ scale was particularly better than just using a double precision. There's
already an interval_div function in the catalog which take an interval and a
double precision and returns an interval, so using floating point math
already has precedent. I figured that if I went with numeric, I'd also have
to have a pretty good reason to change the existing operator or it'd
inconsistent. Since float (without parameters) is both shorter to type and
appears to be the same as double precision (at least according to the docs),
my innate lazy streak went that way.

Am I missing something obvious?

Andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Neil Conway 2007-05-18 00:36:28 Re: CREATE TABLE LIKE INCLUDING INDEXES support
Previous Message Tom Lane 2007-05-17 23:51:34 Re: What is happening on buildfarm member baiji?