Re: [SQL] Interval subtracting

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Markus Schaber <schabi(at)logix-tt(dot)com>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Milen A(dot) Radev" <milen(at)radev(dot)net>, pgsql-sql(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [SQL] Interval subtracting
Date: 2006-03-08 15:47:47
Message-ID: 1141832866.6249.7.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches pgsql-sql

On Wed, 2006-03-08 at 06:07, Markus Schaber wrote:
> Hi, Scott,
>
> Scott Marlowe wrote:
>
> >>But it isn't '-2 months, -1 day'. I think what you are saying is what I
> >>am saying, that we should make the signs consistent.
> > Pretty much. It just seems wrong to have different signs in what is
> > essentially a single unit.
> >
> > We don't say 42 degrees, -12 minutes when measuring arc, do we? Then
> > again, maybe some folks do. It just seems wrong to me.
>
> But we say "quarter to twelve", at least in some areas on this planet.
>
> The problem is that months have different lengths. '2 months - 1 day'
> can be '1 month 27 days', '1 month 28 days', '1 month 29 days' or '1
> month 30 days', depending on the timestamp we apply the interval.

I made this point before. In the military they say 1145 or 2345 instead
of quarter to twelve, because 1: there are two "quarter to twelves" a
day, and 2: It's easy to get it confused.

For same reasons, i.e. a need for precision, I find it hard to accept
the idea of mixing positive and negative units in the same interval.
The plus or minus sign should be outside of the interval.

Then, it's quite certain what you mean. If you say

select '2006-06-12'::date - interval '1 month 2 days'

there is no ambiguity. If you say:

select '2006-06-12'::date + interval '-1 month -2 days'

do you mean (1 month - 2 days) subtracted from the date, or
do you mean to subtract 1 month, then 2 days from the date?

Putting the + or - outside the interval seems to make the most sense to
me. Allowing them inside makes no sense to me. And colloquialisms
aren't really a good reason. :)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-03-08 15:52:39 Re: Running out of disk space during query
Previous Message David Fetter 2006-03-08 15:47:21 Add switches for DELIMITER and NULL in pg_dump COPY

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2006-03-08 15:54:18 Re: [SQL] Interval subtracting
Previous Message David Fetter 2006-03-08 15:47:21 Add switches for DELIMITER and NULL in pg_dump COPY

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2006-03-08 15:54:18 Re: [SQL] Interval subtracting
Previous Message Markus Schaber 2006-03-08 12:07:27 Re: [SQL] Interval subtracting