Re: A proposal for Interval Math

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: josh(at)agliodbs(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: A proposal for Interval Math
Date: 2002-05-20 07:54:51
Message-ID: 1021881291.1452.189.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sun, 2002-05-19 at 22:21, Josh Berkus wrote:

> However, I'll continue pushing for some solution that allows me to calculate
> pay periods in real intervals.

But this is a matter for your local business rules. If someone is paid
monthly and leaves one week into the month, there must be a local rule
to determine what proportion of his monthly pay he gets - is it always
7/28 or 7/30 or is it 7/{28,29,30,31} according to which month it is?
You are proposing a mathematical operation that looks exact but actually
has a fuzzy result and the reason it is fuzzy is that you are trying to
shortcut the process of deciding what rule to apply.

You mentioned calculating the number of 2-week intervals in an interval
column: if you need to do this, the column should not be defined as YEAR
TO MONTH but as DAY (of course, PostgreSQL hasn't yet implemented these
subtypes of INTERVAL). If you *have* to do it with a YEAR TO MONTH
column, you have implicitly defined a local rule that averages out the
difference in month lengths, because in a YEAR-MONTH interval, you don't
know how long a year or a month is. You gave the example

interval_round('7 months','days') / '3 days' = 70

which seems to assume that a month is 30 days. On a different basis the
result would be 365.2425 * 7 / 12 / 3 = 71.019375 or 365 * 7 / 12 / 3
= 70.972222. Both of those round to 71 days. Your 7 months interval is
anything from 209 to 213 days depending on which months it includes,
which is unknowable without a context.

So if you define interval_round() you must also include some means of
configuring what rule to use, because that is not necessarily going to
be the same in every organisation. It might not even be the same
between different applications in one organisation.
--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C

"For all that is in the world, the lust of the flesh,
and the lust of the eyes, and the pride of life, is
not of the Father, but is of the world."
I John 2:17

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Eckhard Hoeffner 2002-05-20 14:08:36 Using LASTOID in one query
Previous Message Josh Berkus 2002-05-19 21:21:05 Re: A proposal for Interval Math