Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bc4Iw-0001z1-AF for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Aug 2016 05:31:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bc4Iv-0003sa-OA for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Aug 2016 05:31:17 +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 1bc4HW-0000HF-My for pgsql-hackers@postgresql.org; Tue, 23 Aug 2016 05:29:51 +0000 Received: from nm22-vm5.bullet.mail.sg3.yahoo.com ([106.10.151.52]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bc4HT-0001jt-Bl for pgsql-hackers@postgresql.org; Tue, 23 Aug 2016 05:29:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.in; s=s2048; t=1471930183; bh=pZRjp7Ciu+Sn05qvALrBwzi9N5OTA9Z8EqyicH0Dmv4=; h=Date:From:Reply-To:To:Cc:In-Reply-To:References:Subject:From:Subject; b=uen47s2/iEgdShMDAdEXo3TRWFlN2DVGpDsS8UUYwO/4JcuYeHEbfYu+qC0Q+kJ3odKvGp9R0LPjM4+AH+EKmbQaHX3m+hf1MpRTCjVtCe3QnWeKOFHeTe15I+mHy1ts5SGjR87AWTf0IXoU7C04IKRAPxT6gM03tX3tdh6Vz3c0Vmh9bByCoo93PhI9TFGm66DNDPoYkwsXNVBnJUy+2aHJ7Vbp2KGMjaQ1BuMqj4oZFy9e7uOxVZm5u5TEZjFvfCAz6U0zBJZu9Or/3j+GYTwKNNH17HBj6Lc6KBNZIiWPtr6zbRQiYQfwwZPRD5ix8w6Tw4Jrz4BTG3zFwEwaNg== Received: from [106.10.166.126] by nm22.bullet.mail.sg3.yahoo.com with NNFMP; 23 Aug 2016 05:29:43 -0000 Received: from [106.10.151.186] by tm15.bullet.mail.sg3.yahoo.com with NNFMP; 23 Aug 2016 05:29:42 -0000 Received: from [127.0.0.1] by omp1012.mail.sg3.yahoo.com with NNFMP; 23 Aug 2016 05:29:42 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 979508.94516.bm@omp1012.mail.sg3.yahoo.com X-YMail-OSG: W6_vglwVM1leIXWw1fylHei_s9gXDybhSIZZB5jbwHhVrWycr1aaoO.dDnxVdjZ 5PHYyN9yHvcKvU2WRcyTArxp.LpCYUCTArH8nmBfxWuWMkpZiwAmxISoH3OEUoRHc9NA22X0V4gI onyXkGDtWvZLCN.X1GzuA5_SO4wDCYGUkRZkA1cZzDFGZX2RrTotfk4hpLA.MaDDRxB9OUEBZ3lY 4Z1Is4EINzJDo1wyvT50gjn2mdJl3fQTlyiiAms9soB4vA0nPrA_oR.sAcndXCRllwAFrYiK77hz r0M_A0AfOQydDbcNbPECRf.jzFluDYnNAJTmol.ynVnThiCwq7wbQxQKJlyTcWFk8sHHcPLlIkP5 aZ0Rmhe0.4OO0GW..N7i0GKF6IBSYixXcPhvzwszja7K2G5lc8YNzz5mXGuwAACxU3kBlJqn56nu vhy2WflSy0XsP4_KmYhtpLGsyMKDt707TQmn5wIhf__eNqIUh6PKFg4bpPGtgDnbQJjlOXvY81mf FF6nOw65i0wu9vqK9FR2G22gaBg-- Received: from jws10961.mail.sg3.yahoo.com by sendmailws102.mail.sg3.yahoo.com; Tue, 23 Aug 2016 05:29:42 +0000; 1471930182.611 Date: Tue, 23 Aug 2016 05:28:37 +0000 (UTC) From: amul sul Reply-To: amul sul To: Artur Zakirov , Robert Haas Cc: Pavel Stehule , Tom Lane , "David G. Johnston" , Alex Ignatov , Bruce Momjian , PostgreSQL-development Message-ID: <234265385.16298751.1471930117094.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <60cc3122-0950-e455-21fe-de89882e285d@postgrespro.ru> References: <1873520224.1784572.1465833145330.JavaMail.yahoo.ref@mail.yahoo.com> <884791796.213185.1466667686999.JavaMail.yahoo@mail.yahoo.com> <20160623133001.GF21246@momjian.us> <1877e60a-a970-18b5-453c-e342f96150e6@postgrespro.ru> <31915.1466703655@sss.pgh.pa.us> <32684.1466704957@sss.pgh.pa.us> <734e50cd-c563-4afd-d1c8-80f244b3265e@postgrespro.ru> <1285870380.13225431.1471272994354.JavaMail.yahoo@mail.yahoo.com> <60cc3122-0950-e455-21fe-de89882e285d@postgrespro.ru> Subject: Re: Bug in to_timestamp(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Length: 2728 X-Pg-Spam-Score: -2.7 (--) 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 Hi Artur Zakirov, Please see following review comment for "0001-to-timestamp-format-checking-v2.patch" & share your thought: #1. 15 + to_timestamp('2000----JUN', 'YYYY MON') Documented as working case, but unfortunatly it does not : postgres=# SELECT to_timestamp('2000----JUN', 'YYYY MON'); ERROR: invalid value "---" for "MON" DETAIL: The given value did not match any of the allowed values for this field. #2. 102 + /* Previous character was a quote */ 103 + else if (in_text) 104 + { 105 + if (*str == '"') 106 + { 107 + str++; 108 + in_text = false; 109 + } 110 + else if (*str == '\\') 111 + { 112 + str++; 113 + in_backslash = true; 114 + } 115 + else 116 + { 117 + n->type = NODE_TYPE_CHAR; 118 + n->character = *str; 119 + n->key = NULL; 120 + n->suffix = 0; 121 + n++; 122 + str++; 123 + } 124 + continue; 125 + } 126 + NODE_TYPE_CHAR assumption in else block seems incorrect. What if we have space after double quote? It will again have incorrect output without any error, see below: postgres=# SELECT to_timestamp('Year: 1976, Month: May, Day: 16', postgres(# '" Year:" YYYY, "Month:" FMMonth, "Day:" DD'); to_timestamp ------------------------------ 0006-05-16 00:00:00-07:52:58 (1 row) I guess, we might need NODE_TYPE_SEPARATOR and NODE_TYPE_SPACE check as well? #3. 296 - /* Ignore spaces before fields when not in FX (fixed width) mode */ 297 + /* Ignore spaces before fields when not in FX (fixed * width) mode */ 298 if (!fx_mode && n->key->id != DCH_FX) 299 { 300 - while (*s != '\0' && isspace((unsigned char) *s)) 301 + while (*s != '\0' && (isspace((unsigned char) *s))) 302 s++; Unnecessary hunk? We should not touch any code unless it necessary to implement proposed feature, otherwise it will add unnecessary diff to the patch and eventually extra burden to review the code. Similarly hunk in the patch @ line # 313 - 410, nothing to do with to_timestamp behaviour improvement, IIUC. If you think this changes need to be in, please submit separate cleanup-patch. >I attached second patch "0002-to-timestamp-validation-v2.patch". With it >PostgreSQL perform additional checks for date and time. But as I wrote >there is another patch in the thread "to_date_valid()" wich differs from >this patch. @community : I am not sure what to do with this patch, should we keep it as separate enhancement? Regards, Amul Sul -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers