Add operator for dividing interval by an interval

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Add operator for dividing interval by an interval
Date: 2023-05-18 20:49:11
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I've open-coded $subject many times. I wonder if we should add at least a
restricted version of it.

I did find one past discussion of it on the list:

We have workarounds for it on the wiki:

There are plenty of search results with various, often quite wrong,

Of course, it's true that there are plenty intervals where division would not
result in clearly determinable result. E.g. '1 month'::interval / '1 day'::interval.

I think there's no clear result whenever the month component is non-zero,
although possibly there are some cases of using months that could be made work
(e.g. '12 months' / '1 month').

In the cases I have wanted interval division, I typically dealt with intervals
without the month component - typically the intervals are the result of
subtracting timestamps or such.

One typical usecase for me is to divide the total runtime of a benchmark by
the time taken for some portion of that (e.g. time spent waiting for IO).

What about an interval / interval -> double operator that errors out whenever
month is non-zero? As far as I can tell that would always be deterministic.


Andres Freund


Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2023-05-18 20:49:47 PG 16 draft release notes ready
Previous Message Tom Lane 2023-05-18 20:03:36 Re: The documentation for READ COMMITTED may be incomplete or wrong