Re: BUG #8216: TO_DATE does not support th format provided

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: sunitha(dot)mudumba(at)blss(dot)com(dot)au
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #8216: TO_DATE does not support th format provided
Date: 2013-06-07 13:41:45
Message-ID: 21659.1370612505@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

sunitha(dot)mudumba(at)blss(dot)com(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Isaac Morland 2013-06-07 13:43:30 Re: BUG #8215: pg_dump includes table out of order in SQL dump
Previous Message Federico Campoli 2013-06-07 13:08:33 Re: BUG #8192: On very large tables the concurrent update with vacuum lag the hot_standby replica