pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Abraham, Danny <danny_abraham@bmc.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: date function bug
Date: Wed, 23 Oct 2019 10:44:52 -0400
Message-ID: <21348.1571841892@sss.pgh.pa.us> (raw)
In-Reply-To: <0bac35bcde6747e485bc7468c4080798@phx-exmbprd-01.adprod.bmc.com>
References: <0bac35bcde6747e485bc7468c4080798@phx-exmbprd-01.adprod.bmc.com>

"Abraham, Danny" <danny_abraham@bmc.com> writes:
> The function "to_date" does not fail illegal values.
> Is this a known bug?

No, it's a feature, because the point of to_date() is to parse strings
that would be rejected or misinterpreted by the regular date input
function.  If you want tighter error checking and your input is supposed
to follow a common format, just cast the string to date.

regression=# select '2018100X'::date;
ERROR:  invalid input syntax for type date: "2018100X"
LINE 1: select '2018100X'::date;
               ^
regression=# select '20181501'::date;
ERROR:  date/time field value out of range: "20181501"
LINE 1: select '20181501'::date;
               ^
HINT:  Perhaps you need a different "datestyle" setting.
regression=# select '20181001'::date;
    date    
------------
 2018-10-01
(1 row)

			regards, tom lane





view thread (11+ messages)  latest in thread

Message-ID: <21348.1571841892@sss.pgh.pa.us>
Permalink:  ../21348.1571841892@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21348.1571841892@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, danny_abraham@bmc.com
  Subject: Re: date function bug
  In-Reply-To: <21348.1571841892@sss.pgh.pa.us>
  References: <0bac35bcde6747e485bc7468c4080798@phx-exmbprd-01.adprod.bmc.com> <21348.1571841892@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox