mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Add option to use ICU as global locale provider
This adds the option to use ICU as the default locale provider for either the whole cluster or a database. New options for initdb, createdb, and CREATE DATABASE are used to select this. Since some (legacy) code still uses the libc locale facilities directly, we still need to set the libc global locale settings even if ICU is otherwise selected. So pg_database now has three locale-related fields: the existing datcollate and datctype, which are always set, and a new daticulocale, which is only set if ICU is selected. A similar change is made in pg_collation for consistency, but in that case, only the libc-related fields or the ICU-related field is set, never both. Reviewed-by: Julien Rouhaud <rjuju123@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/5e756dd6-0e91-d778-96fd-b1bcb06c161a%402ndquadrant.com
This commit is contained in:
@ -318,6 +318,7 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
|
||||
bool isnull;
|
||||
char *collate;
|
||||
char *ctype;
|
||||
char *iculocale;
|
||||
|
||||
/* Fetch our pg_database row normally, via syscache */
|
||||
tup = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(MyDatabaseId));
|
||||
@ -420,6 +421,24 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
|
||||
" which is not recognized by setlocale().", ctype),
|
||||
errhint("Recreate the database with another locale or install the missing locale.")));
|
||||
|
||||
if (dbform->datlocprovider == COLLPROVIDER_ICU)
|
||||
{
|
||||
datum = SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_daticulocale, &isnull);
|
||||
Assert(!isnull);
|
||||
iculocale = TextDatumGetCString(datum);
|
||||
make_icu_collator(iculocale, &default_locale);
|
||||
}
|
||||
else
|
||||
iculocale = NULL;
|
||||
|
||||
default_locale.provider = dbform->datlocprovider;
|
||||
/*
|
||||
* Default locale is currently always deterministic. Nondeterministic
|
||||
* locales currently don't support pattern matching, which would break a
|
||||
* lot of things if applied globally.
|
||||
*/
|
||||
default_locale.deterministic = true;
|
||||
|
||||
/*
|
||||
* Check collation version. See similar code in
|
||||
* pg_newlocale_from_collation(). Note that here we warn instead of error
|
||||
@ -434,7 +453,7 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
|
||||
|
||||
collversionstr = TextDatumGetCString(datum);
|
||||
|
||||
actual_versionstr = get_collation_actual_version(COLLPROVIDER_LIBC, collate);
|
||||
actual_versionstr = get_collation_actual_version(dbform->datlocprovider, dbform->datlocprovider == COLLPROVIDER_ICU ? iculocale : collate);
|
||||
if (!actual_versionstr)
|
||||
ereport(WARNING,
|
||||
(errmsg("database \"%s\" has no actual collation version, but a version was recorded",
|
||||
|
Reference in New Issue
Block a user