Re: Validity check in to_date?

From: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
To: Christoph Haller <ch(at)rodos(dot)fzk(dot)de>
Cc: "Alexander M(dot) Pravking" <fduch(at)antar(dot)bryansk(dot)ru>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Validity check in to_date?
Date: 2003-12-02 09:57:14
Message-ID: 20031202095713.GB17884@zf.jcu.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Dec 02, 2003 at 10:27:04AM +0100, Christoph Haller wrote:
> >
> > I just discovered that to_date() function does not check if supplied
> > date is correct, giving surprising (at least for me) results:
> >
> > fduch=# SELECT to_date('31.11.2003', 'DD.MM.YYYY');
> > to_date
> > ------------
> > 2003-12-01
> >
> > or even
> >
> > fduch=# SELECT to_date('123.45.2003', 'DD.MM.YYYY');
> > to_date
> > ------------
> > 2007-01-03
> >
> > to_timestamp() seems to work the same way. It's probably useful sometimes,
> > but not in my case... Is it how it supposed to work?
> > If so, how can I do such a validity check?
> > If not, has something changed in 7.4?

No change in 7.4. Maybe in 7.5 or in some 7.4.x.

> As far as I know these results are correct in terms of the underlying
> C-library function mktime(). This function is intended to be used when
> adding/subtracting intervals from a given timestamp.
> I don't know of any postgres function doing the check you're looking for.
> But I can't believe this is the first time this topic is brought up.
> You may search the archives on "date plausibility" are related terms.

The others PostgreSQL stuff which full parse (means check ranges)
date/time is less optimistic with this:

# select '31.11.2003'::date;
ERROR: date/time field value out of range: "31.11.2003"

Karel

--
Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
http://home.zf.jcu.cz/~zakkr/

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message CoL 2003-12-02 10:17:52 Re: Validity check in to_date?
Previous Message Richard Huxton 2003-12-02 08:56:05 Re: Problem with intervals