Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bi1Jg-0003sT-6H for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Sep 2016 15:32:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bi1Je-0004nP-SK for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Sep 2016 15:32:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bi1IG-00033u-4H for pgsql-hackers@postgresql.org; Thu, 08 Sep 2016 15:31:12 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bi1ID-0008VA-8a for pgsql-hackers@postgresql.org; Thu, 08 Sep 2016 15:31:10 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id EA03D204FF; Thu, 8 Sep 2016 11:31:07 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute2.internal (MEProxy); Thu, 08 Sep 2016 11:31:08 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=kULWznppZ6DBO5E o+TRq9bq+U8o=; b=MCT2a+nMQ/9P2DKubyD0n3sU57kXdmmth5WKNFA+kBgpcCY ZkTQWheIYVUsnk5tQQNI2TgP0yB6RG1ulkwLrGGjOHjPv800y5I1U1VmmzyIgVnW jRlXT0E/jXL5suPFlR9cgF0l9ENCRjcdI0NnlaXgXPHXtZESKqPdtyRv3BRo= X-Sasl-enc: l5JjDEZ+PYBncRx6XRDPX+tdVBmuTxLpUrdPqzmuSYhm 1473348667 Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id 6F593F2D2D; Thu, 8 Sep 2016 11:31:07 -0400 (EDT) Subject: Re: to_date_valid() To: Andreas 'ads' Scherbaum , Artur Zakirov , "Joshua D. Drake" , Albe Laurenz , 'Andreas Karlsson *EXTERN*' , Pavel Stehule References: <57786490.9010201@wars-nicht.de> <5778EA94.1020706@wars-nicht.de> <2bc6bcef-cada-1ac7-f9a2-2f6128ca4c3c@proxel.se> <579823DF.3080903@commandprompt.com> <95738e12-6ed6-daf5-9dcf-6336072e6b15@postgrespro.ru> <81ed5480-9bca-361b-9aa0-cbafc2ec2f63@wars-nicht.de> Cc: Jaime Casanova , Euler Taveira , Pg Hackers From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <7fde7a91-0ad3-33ac-c348-cf58e4638464@2ndquadrant.com> Date: Thu, 8 Sep 2016 11:31:06 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <81ed5480-9bca-361b-9aa0-cbafc2ec2f63@wars-nicht.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 8/15/16 7:33 AM, Andreas 'ads' Scherbaum wrote: > postgres=# SELECT to_date('2011 12 18', 'YYYY MM DD'); > to_date > ------------ > 2011-12-08 > (1 row) > > > That is from the regression tests, and obviously handles the date > transformation wrong. My attempt catches this, because I compare the > date with the input date, and do not rely on a valid date only. It's debatable what is correct here. Using to_number, the behavior appears to be that a space in the pattern ignores one character. For example: test=# select to_number('123 456', '999 999'); to_number ----------- 123456 test=# select to_number('123 456', '999 999'); to_number ----------- 12356 Considering that, the above to_date result is not incorrect. So just squashing the spaces and converting the value back is not a correct approach to detecting overflow. I think using ValidateDate() was the right idea. That is what we use for checking date validity everywhere else. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers