From: | "Daniel Verite" <daniel(at)manitou-mail(dot)org> |
---|---|
To: | "Michael Paquier" <michael(at)paquier(dot)xyz> |
Cc: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>,"Alvaro Herrera" <alvherre(at)2ndquadrant(dot)com>,pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: Create collation reporting the ICU locale display name |
Date: | 2019-09-13 13:57:10 |
Message-ID: | 95e6c4f0-34b3-47f8-8c29-ebe2b22c3797@manitou-mail.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Michael Paquier wrote:
> Or could it make sense to provide a system function which returns a
> collation description for at least an ICU-provided one? We could make
> use of that in psql for example.
If we prefer having a function over the instant feedback effect of
the NOTICE, the function might look like icu_collation_attributes() [1]
from the icu_ext extension. It returns a set of (attribute,value)
tuples, among which the displayname is one of the values.
An advantage of this approach is that you may execute the
function before creating the collation, instead of creating the
collation, realizing there was something wrong in your
locale/lc_collate argument, dropping the collation and trying again.
Another advantage would be the possibility of localizing the
display name, leaving the localization as a choice to the user.
Currently get_icu_locale_comment() forces "en" as the language because
it want results in US-ASCII, but a user-callable function could have the
language code as an optional argument. When not being forced, the
language has a default value obtained by ICU from the environment
(so that would be from where the postmaster is started in our case),
and is also settable with uloc_setDefault().
Example with icu_ext functions:
test=> select icu_set_default_locale('es');
icu_set_default_locale
------------------------
es
test=> select value from icu_collation_attributes('en-US-u-ka-shifted')
where attribute='displayname';
value
--------------------------------------------
inglés (Estados Unidos, alternate=shifted)
This output tend to reveal mistakes with tags, which is why I thought
to expose it as a NOTICE. It addresses the case of a user
who wouldn't suspect an error, so the "in-your-face" effect is
intentional. With the function approach, the user must be
proactive.
An example of mistake I found myself doing is forgetting the '-u-' before
the collation tags, which doesn't error out but is detected relatively
easily with the display name.
-- wrong
test=> select value from icu_collation_attributes('de-DE-ks-level1')
where attribute='displayname';
value
-----------------------------
German (Germany, KS_LEVEL1)
-- right
test=> select value from icu_collation_attributes('de-DE-u-ks-level1')
where attribute='displayname';
value
---------------------------------------
German (Germany, colstrength=primary)
[1] https://github.com/dverite/icu_ext#icu_collation_attributes
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
From | Date | Subject | |
---|---|---|---|
Next Message | Nikita Glukhov | 2019-09-13 14:20:30 | Re: Bug in GiST paring heap comparator |
Previous Message | Virendra Negi | 2019-09-13 13:11:24 | Primary keepalive message not appearing in Logical Streaming Replication |