Re: Allow to_date() and to_timestamp() to accept localized names

From: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Allow to_date() and to_timestamp() to accept localized names
Date: 2019-09-18 09:09:52
Message-ID: CAC+AXB1ao4uniAXNnWU3uyq6Ks=nyKq5MwzrFM8sw_MLUF+E=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 13, 2019 at 10:31 PM Alvaro Herrera
<alvherre(at)2ndquadrant(dot)com> wrote:
>
Thanks for taking a look at this.

> I'm confused why we acquire the MONTH_DIM / etc definitions. Can't we
> just use lengthof() of the corresponding array? AFAICS it should work
> just as well.
>

It was because of the length difference between ascii-name arrays,
which were all null-ended, and localized-name arrays. The attached
version uses lengthof().

> I wonder if the "compare first char" thing (seq_search_localized) really
> works when there are multibyte chars in the day/month names. I think
> the code compares just the first char ... but what if the original
> string uses those funny Unicode non-normalized letters and the locale
> translation uses normalized letters? My guess is that the first-char
> comparison will fail, but surely you'll want the name to match.
> (There's no month/day name in Spanish that doesn't start with an ASCII
> letter, but I bet there are some in other languages.) I think the
> localized comparison should avoid the first-char optimization, just
> compare the whole string all the time, and avoid possible weird issues.

The localized search is reformulated in this version to deal with
multibyte normalization. A regression test for this issue is included.

Regards,

Juan José Santamaría Flecha

Attachment Content-Type Size
0001-Allow-localized-month-names-to_date-v2.patch application/octet-stream 17.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2019-09-18 09:11:02 Re: Add a GUC variable that control logical replication
Previous Message Quan Zongliang 2019-09-18 08:39:31 Add a GUC variable that control logical replication