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 1iv0lE-0001Cw-1G for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Jan 2020 15:20:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iv0lC-0005pJ-Cd for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Jan 2020 15:20:38 +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 1iv0lC-0005nT-3c for pgsql-hackers@lists.postgresql.org; Fri, 24 Jan 2020 15:20:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iv0l9-0006SF-H3 for pgsql-hackers@lists.postgresql.org; Fri, 24 Jan 2020 15:20:37 +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 00OFKUr1028024; Fri, 24 Jan 2020 10:20:30 -0500 From: Tom Lane To: =?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= cc: Alvaro Herrera , Arthur Zakirov , Tomas Vondra , PostgreSQL Hackers Subject: Re: Allow to_date() and to_timestamp() to accept localized names In-reply-to: References: <20200123164955.GA23074@alvherre.pgsql> <20326.1579816853@sss.pgh.pa.us> Comments: In-reply-to =?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= message dated "Fri, 24 Jan 2020 10:48:19 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <28022.1579879230.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 24 Jan 2020 10:20:30 -0500 Message-ID: <28023.1579879230@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?UTF-8?Q?Juan_Jos=3DC3=3DA9_Santamar=3DC3=3DADa_Flecha?=3D writes: > On Thu, Jan 23, 2020 at 11:00 PM Tom Lane wrote: >> * It's not exactly apparent to me why this code should be concerned >> about non-normalized characters when noplace else in the backend is. > There is an open patch that will make the normalization functionality us= er > visible [1]. So, if a user can call to_date(normalize('01 =C5=9EUB 2010'= ), 'DD > TMMON YYYY') I would vote to drop the normalization logic inside this pa= tch > altogether. Works for me. > * I have no faith in this calculation that decides how long the match >> length was: >> *len =3D element_len + name_len - norm_len; > The proper logic would come from do_to_timestamp() receiving a normalize= d > "date_txt" input, so we do not operate with unnormalize and normalize > strings at the same time. No, that only solves half the problem, because the downcasing transformation can change the string length too. Two easy examples: * In German, I believe "=C3=9F" downcases to "ss". In Latin-1 encoding th= at's a length change, though I think it might accidentally not be in UTF8. * The Turks distinguish dotted and dotless "i", so that "=C4=B0" downcases= to "i", and conversely "I" downcases to "=C4=B1". Those are length changes i= n UTF8, though not in whichever Latin-N encoding works for Turkish. Even if these cases happen not to apply to any month or day name of the relevant language, we still have a problem, arising from the fact that we're downcasing the whole remaining string --- so length changes after the match could occur anyway. > I would like to rise a couple of questions myself: > * When compiled with DEBUG_TO_FROM_CHAR, there is a warning "=E2=80=98du= mp_node=E2=80=99 > defined but not used". Should we drop this function or uncomment its usa= ge? Maybe, but I don't think it belongs in this patch. > * Would it be worth moving str_tolower(localized_name) > from seq_search_localized() into cache_locale_time()? I think it'd complicate tracking when that cache has to be invalidated (i.e. it now depends on more than just LC_TIME). On the whole I wouldn't bother unless someone does the measurements to show there'd be a useful speedup. regards, tom lane