+
. The
+ linkend="create-database-locale-provider">locale provider must
+ be
builtin . The default is the setting of
+ linkend="create-database-locale"/> if specified; otherwise the same
+ setting as the template database. Currently, the only available
+ locale for the builtin provider is
+ C .
+
+
+
+
icu_locale
if (collprovider == COLLPROVIDER_BUILTIN)
{
- collencoding = GetDatabaseEncoding( );
+ collencoding = builtin_locale_encoding(colllocale );
}
else if (collprovider == COLLPROVIDER_ICU)
{
if (collform->collprovider == COLLPROVIDER_BUILTIN)
{
- Datum datum;
- const char *colllocale;
-
- datum = SysCacheGetAttrNotNull(COLLOID, tp, Anum_pg_collation_colllocale);
- colllocale = TextDatumGetCString(datum);
-
cache_entry->collate_is_c = true;
- cache_entry->ctype_is_c = (strcmp(colllocale, "C") == 0) ;
+ cache_entry->ctype_is_c = true ;
}
else if (collform->collprovider == COLLPROVIDER_LIBC)
{
return result;
}
+/*
+ * Return required encoding ID for the given locale, or -1 if any encoding is
+ * valid for the locale.
+ *
+ * The only supported locale for the builtin provider is "C", and it's
+ * available for any encoding.
+ */
+int
+builtin_locale_encoding(const char *locale)
+{
+ if (strcmp(locale, "C") == 0)
+ return -1;
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("invalid locale name \"%s\" for builtin provider",
+ locale)));
+}
+
+
/*
* Validate the locale and encoding combination, and return the canonical form
* of the locale name.
" set default locale in the respective category for\n"
" new databases (default taken from environment)\n"));
printf(_(" --no-locale equivalent to --locale=C\n"));
- printf(_(" --builtin-locale=LOCALE set builtin locale name for new databases\n"));
+ printf(_(" --builtin-locale=LOCALE\n"
+ " set builtin locale name for new databases\n"));
printf(_(" --locale-provider={builtin|libc|icu}\n"
" set default locale provider for new databases\n"));
printf(_(" --pwfile=FILE read password for the new superuser from file\n"));
else
{
printf(_("The database cluster will be initialized with this locale configuration:\n"));
- printf(_(" default collation provider: %s\n"), collprovider_name(locale_provider));
+ printf(_(" locale provider: %s\n"), collprovider_name(locale_provider));
if (locale_provider != COLLPROVIDER_LIBC)
- printf(_(" default collation locale: %s\n"), datlocale);
+ printf(_(" default collation: %s\n"), datlocale);
printf(_(" LC_COLLATE: %s\n"
" LC_CTYPE: %s\n"
" LC_MESSAGES: %s\n"
'--lc-monetary=C', '--lc-time=C',
"$tempdir/data4"
],
- qr/^\s+default collation locale :\s+und\n/ms,
+ qr/^\s+default collation:\s+und\n/ms,
'options --locale-provider=icu --locale=und --lc-*=C');
command_fails_like(
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 202403172
+#define CATALOG_VERSION_NO 202403181
#endif
extern size_t pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src,
size_t srclen, pg_locale_t locale);
+extern int builtin_locale_encoding(const char *loc_str);
extern const char *builtin_validate_locale(int encoding, const char *loc_str);
extern void icu_validate_locale(const char *loc_str);
extern char *icu_language_tag(const char *loc_str, int elevel);
0,
"C locale works for ICU");
+# Test that LOCALE works for ICU locales if LC_COLLATE and LC_CTYPE
+# are specified
+is( $node1->psql(
+ 'postgres',
+ q{CREATE DATABASE dbicu2 LOCALE_PROVIDER icu LOCALE '@colStrength=primary'
+ LC_COLLATE='C' LC_CTYPE='C' TEMPLATE template0 ENCODING UTF8}
+ ),
+ 0,
+ "LOCALE works for ICU locales if LC_COLLATE and LC_CTYPE are specified");
+
my ($ret, $stdout, $stderr) = $node1->psql('postgres',
- q{CREATE DATABASE dbicu LOCALE_PROVIDER builtin LOCALE 'C' TEMPLATE dbicu}
+ q{CREATE DATABASE dbicu3 LOCALE_PROVIDER builtin LOCALE 'C' TEMPLATE dbicu}
);
isnt($ret, 0, "locale provider must match template: exit code not 0");
like(