Allow to_date() and to_timestamp() to accept localized month names

From: Mattia <mattia(at)p2pforum(dot)it>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Allow to_date() and to_timestamp() to accept localized month names
Date: 2016-09-10 10:18:04
Message-ID: CA+heTbrDQ6b0Am_mk0dJEcwNxwQz+r=az_=zHTva+5BDnfOKjA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,
attached is a patch which adds support to localized month names in
to_date() and to_timestamp() functions.

The patch is fairly simple but I want to discuss the approach and
implementation:

Using the TM modifier as in to_char() was already discussed some years
ago: 10710(dot)1202170898(at)sss(dot)pgh(dot)pa(dot)us [1]

I thought about reusing from_char_seq_search() but localized month
names use different capitalization according to the language grammar,
so I used pg_strncasecmp to do the match.

Regression tests with TM modifier are difficult since one should have
the locale used for the test installed on his system.

Usage example:
postgres=# set lc_time to 'fr_FR';
SET
postgres=# select to_date('22 janvier 2016', 'DD TMMonth YYYY');
to_date
------------
2016-01-22
(1 row)

[1] https://www.postgresql.org/message-id/10710.1202170898%40sss.pgh.pa.us

Thanks
Mattia

Attachment Content-Type Size
localized_month_names_v1.patch application/x-download 3.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2016-09-10 10:35:22 Re: Logical Replication WIP
Previous Message Peter Eisentraut 2016-09-10 09:27:45 Re: pg_basebackup, pg_receivexlog and data durability (was: silent data loss with ext4 / all current versions)