Re: BUG #8216: TO_DATE does not support th format provided - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #8216: TO_DATE does not support th format provided
Date
Msg-id 21659.1370612505@sss.pgh.pa.us
Whole thread Raw
In response to BUG #8216: TO_DATE does not support th format provided  (sunitha.mudumba@blss.com.au)
List pgsql-bugs
sunitha.mudumba@blss.com.au writes:
> To_date does not throw an error when an invalid date is provided to it
> select to_date('10-30-2012','dd-MM-YYYY');

That's not a bug; it's operating as designed.  If you want more error
checking, don't use to_date() --- just cast the string to date.

regression=# show datestyle;
 DateStyle
-----------
 ISO, MDY
(1 row)

regression=# select '10-30-2012'::date;
    date
------------
 2012-10-30
(1 row)

regression=# set datestyle = dmy;
SET
regression=# select '10-30-2012'::date;
ERROR:  date/time field value out of range: "10-30-2012"
LINE 1: select '10-30-2012'::date;
               ^
HINT:  Perhaps you need a different "datestyle" setting.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Federico Campoli
Date:
Subject: Re: BUG #8192: On very large tables the concurrent update with vacuum lag the hot_standby replica
Next
From: Isaac Morland
Date:
Subject: Re: BUG #8215: pg_dump includes table out of order in SQL dump