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