Re: help: now() + N is now failing!

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Dmitry Tkach <dmitry(at)openratings(dot)com>
Cc: <mel(at)gmanmi(dot)tv>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: help: now() + N is now failing!
Date: 2003-07-29 17:30:14
Message-ID: 20030729102452.P92021-100000@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, 29 Jul 2003, Dmitry Tkach wrote:

> Stephan Szabo wrote:
>
> >On Tue, 29 Jul 2003, Dmitry Tkach wrote:
> >
> >
> >
> >>Yeah... Looks weird.
> >>For some reason, even date_pli(now(), 2) doesn't work any more - you
> >>have to do date_pli(now()::date,2)
> >>I guess, the now()+2 has the same problem - for some reason, it fails to
> >>coerce timestamptz into date automatically :-(
> >>Why is that? There is only one function called date_pli(), and there is
> >>an unambigous conversion date(timestamptz)... Why does it now force the
> >>user to cast explicitly???
> >>
> >>
> >
> >It's not an implicit cast any longer (see pg_cast). Implicit casts often
> >result in unexpected behavior.
> >
> >For example, what should now()+2 mean? Converting to date and adding two
> >days is fairly wierd behavior, I'd much more expect it to say add 2
> >seconds or error. now() + interval '2 days' or cast(now() as date)+2 both
> >express the intent of adding 2 days much better.
> >
> >
> Ok, granted that, but what's wrong with date_pli (now(), 2)?

It's a similar issue. As a potential counter example, what about
date_pli('foo', 2) or date_pli(inet '1.1.1.1', 2)? There's a cast
from text->date and a cast inet->text. If you allow downcasts and
arbitrary casts you can get some really odd behavior.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Robert Treat 2003-07-29 18:27:15 Re: switch statement in plpgsql
Previous Message Mel Jamero 2003-07-29 16:28:40 Re: any idea regarding this error?