Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGQsr-0006au-3g for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Nov 2017 14:47:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGQsq-0007DC-88 for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Nov 2017 14:47:44 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eGQsp-0007D1-W5 for pgsql-hackers@lists.postgresql.org; Sun, 19 Nov 2017 14:47:44 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eGQsl-0004BJ-EU for pgsql-hackers@postgresql.org; Sun, 19 Nov 2017 14:47:43 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id A2FCE21C172B; Sun, 19 Nov 2017 17:47:37 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from arthur.localdomain (ppp91-76-167-87.pppoe.mtu-net.ru [91.76.167.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 5598621C0909; Sun, 19 Nov 2017 17:47:37 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1511102857; bh=LJ808d0tvZE57fujiIQOvWKjkwAzSWuHAY7Y9tD/GQw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=BWP/YOnSlvAOVknTQaI49MeWkvwtan9Jj+PYZoQPVRCdsQnTwh4wgmfzMa5cUPbVD i5C9ftqlUE2jtwGeSJPw717ILsH4pmA4fiizUFYf5QKtxUxAnVxij+C7ID5PZUBcL8 XxRdM7Wr3Y99Ka45+llhS7E/DHZ2VKfjw2jvRa3s= Date: Sun, 19 Nov 2017 17:47:35 +0300 From: Arthur Zakirov To: Tom Lane Cc: amul sul , Pavel Stehule , Robert Haas , "David G. Johnston" , Alex Ignatov , Bruce Momjian , amul sul , PostgreSQL-development Subject: Re: [HACKERS] Bug in to_timestamp(). Message-ID: <20171119144734.GA12415@arthur.localdomain> References: <32684.1466704957@sss.pgh.pa.us> <734e50cd-c563-4afd-d1c8-80f244b3265e@postgrespro.ru> <29142.1475097531@sss.pgh.pa.us> <8744.1478284597@sss.pgh.pa.us> <29637.1511045306@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <29637.1511045306@sss.pgh.pa.us> User-Agent: Mutt/1.9.1 (2017-09-22) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Nov 18, 2017 at 05:48:26PM -0500, Tom Lane wrote: > This patch needs a rebase over the formatting.c fixes that have gone > in over the last couple of days. > > Looking at the rejects, I notice that in your changes to parse_format(), > you seem to be making it rely even more heavily on remembering state about > the previous input. I recommend against that --- it was broken before, > and it's a pretty fragile approach. Backslashes are not that hard to > deal with in-line. I can continue to work on a better approach. Though, the patch was made a long time ago I'll refresh my memory. The main intent was to fix the following behaviour: =# SELECT TO_TIMESTAMP('2016-06-13 15:43:36', 'YYYY/MM/DD HH24:MI:SS'); to_timestamp ------------------------ 2016-06-13 05:43:36-07 <— incorrect time > select to_timestamp('97/Feb/16', 'YY:Mon:DD') > select to_timestamp('97/Feb/16', 'YY Mon DD') > select to_timestamp('97 Feb 16', 'YY/Mon/DD') > > (Well, Oracle thinks these mean 2097 where we think 1997, but the point is > you don't get an error.) I see from your regression test additions that > you want to make some of these throw an error, and I think that any such > proposal is dead in the water. Nobody is going to consider it an > improvement if it both breaks working PG apps and disagrees with Oracle. > > regards, tom lane If I understand correctly, these queries don't throw an error and the patch tried to follow Oracle's rules. Only queries with FX field throw an error. For example: =# SELECT to_timestamp('97/Feb/16', 'FXYY:Mon:DD'); ERROR: unexpected character "/", expected ":" From Oracle's documentation [1]: > FX - Requires exact matching between the character data and the format model. I agree that compatibility breaking is not good and a fu ure patch may only try to fix wrong output date and time as in Amul's first email. 1 - https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924 -- Arthur Zakirov Postgres Professional: http://www.postgrespro.com Russian Postgres Company