Re: Bug in date arithmetic

From: Greg Stark <gsstark(at)mit(dot)edu>
To: David Fetter <david(at)fetter(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Bug in date arithmetic
Date: 2009-08-24 20:13:09
Message-ID: 407d949e0908241313t20b0e78ekeb524846850cbbef@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Aug 24, 2009 at 8:27 PM, David Fetter<david(at)fetter(dot)org> wrote:
> I'm thinking that the unknown literal here should just cause an error
> in the case of '+'.  Same with '-', for what it's worth.

That would make a lot of people very unhappy. They expect things like

select date + '1 year'

to just work.

The problem is that they would also like

select date - '1year'
and
select date - '2000-01-01'

to work.

I wonder if we could get around this by inventing a new type
date_or_interval which looks at the input and decides which it is
using fairly strict rules. date_sub would take that type and do the
appropriate operation based on what the constant had in it.

Of course we still want to be able to do date1 - date2 or
date1+intervalcolumn so we would need implicit casts from date and
interval to this new type. The question is whether we could arrange
things so this implicit cast doesn't cause ambiguity elsewhere.

--
greg
http://mit.edu/~gsstark/resume.pdf

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2009-08-24 20:17:23 Re: Feedback about Drupal SQL debugging
Previous Message Tom Lane 2009-08-24 19:27:54 Re: hba load error and silent mode