Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNHso-0004w4-He for pgsql-general@arkaria.postgresql.org; Wed, 23 Oct 2019 14:45:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iNHsn-0007cc-8Z for pgsql-general@arkaria.postgresql.org; Wed, 23 Oct 2019 14:45:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNHsm-0007cV-VO for pgsql-general@lists.postgresql.org; Wed, 23 Oct 2019 14:45:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNHsk-0004HS-Qg for pgsql-general@postgresql.org; Wed, 23 Oct 2019 14:45:04 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x9NEiqjx021349; Wed, 23 Oct 2019 10:44:52 -0400 From: Tom Lane To: "Abraham, Danny" cc: "pgsql-general@postgresql.org" Subject: Re: date function bug In-reply-to: <0bac35bcde6747e485bc7468c4080798@phx-exmbprd-01.adprod.bmc.com> References: <0bac35bcde6747e485bc7468c4080798@phx-exmbprd-01.adprod.bmc.com> Comments: In-reply-to "Abraham, Danny" message dated "Wed, 23 Oct 2019 14:22:31 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21347.1571841892.1@sss.pgh.pa.us> Date: Wed, 23 Oct 2019 10:44:52 -0400 Message-ID: <21348.1571841892@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Abraham, Danny" 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