Re: BUG #1871: operations with data types

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: anris(at)polynet(dot)lviv(dot)ua, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1871: operations with data types
Date: 2005-09-11 04:43:58
Message-ID: 2342.1126413838@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Michael Fuhr <mike(at)fuhr(dot)org> writes:
> Apparently the two intervals don't cancel each other out (i.e.,
> they're not optimized to zero),

Well, no, because + and - associate left-to-right.

> so effectively we get this:

> test=> select '2005-08-31'::date + '1 month'::interval;
> ?column?
> ---------------------
> 2005-09-30 00:00:00
> (1 row)

This seems to be the crux of the issue: is the above expression valid
and if so what should it yield?

I think you are right that the SQL spec wants it to raise an error,
but the spec's rules about datetime behavior are uselessly narrow
minded (last I checked, they still had not heard of daylight savings
time ... so they're obviously not trying very hard in this area).

The behavior that's in our code now is to round back to the last real
day of the month. This might not be the best choice, but raising an
error doesn't seem better to me offhand. Date and Darwen seem to
think rounding forward to the first day of the next month would be
more natural. I'm not sure why; it certainly wouldn't fix the
complainant's issue, only surprise him in a different way. Also,
even if you like round-forward for the above case, what about
subtraction --- what should '2005-10-31' - '1 month' give? Rounding
down definitely feels more natural in that case, at least to me.

Any comments out there?

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Fuhr 2005-09-11 05:33:35 Re: BUG #1871: operations with data types
Previous Message Michael Fuhr 2005-09-11 03:37:16 Re: BUG #1870: Insertion problem