Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q2aF8-0000mk-3b for pgsql-hackers@arkaria.postgresql.org; Fri, 26 May 2023 16:24:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q2aF6-0006mr-WE for pgsql-hackers@arkaria.postgresql.org; Fri, 26 May 2023 16:24:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q2aF6-0006mi-N3 for pgsql-hackers@lists.postgresql.org; Fri, 26 May 2023 16:24:40 +0000 Received: from mail.verite.pro ([185.16.44.216]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q2aF3-002IjR-94 for pgsql-hackers@lists.postgresql.org; Fri, 26 May 2023 16:24:40 +0000 Received: by mail.verite.pro (Postfix, from userid 1000) id 10F078C0CFE; Fri, 26 May 2023 18:24:36 +0200 (CEST) MIME-Version: 1.0 From: "Daniel Verite" Subject: Re: Order changes in PG16 since ICU introduction To: "Jeff Davis" Cc: Matthias van de Meent , Andrew Gierth , Peter Eisentraut , Sandro Santilli , Tom Lane , Regina Obe , pgsql-hackers@lists.postgresql.org In-Reply-To: <660e18263897e046e9104cc60c1cea14dc9e7551.camel@j-davis.com> Date: Fri, 26 May 2023 18:24:35 +0200 Message-Id: X-Mailer: Manitou v1.7.3 Content-type: multipart/mixed; boundary="----------=_1685118275-17172-59" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format... ------------=_1685118275-17172-59 Content-Type: text/plain; charset="iso-8859-15" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Jeff Davis wrote: > > #1 > >=20 > > postgres=3D# create database test1 locale=3D'fr_FR.UTF-8'; > > NOTICE: using standard form "fr-FR" for ICU locale "fr_FR.UTF-8" > > ERROR: new ICU locale (fr-FR) is incompatible with the ICU locale of >=20 > I don't see a problem here. If you specify LOCALE to CREATE DATABASE, > you should either be using "TEMPLATE template0", or you should be > expecting an error if the LOCALE doesn't match exactly. >=20 > What would you like to see happen here? What's odd is that initdb starting in an fr_FR.UTF-8 environment found that "fr" was the default ICU locale to use, whereas "create database" reports that "fr" and "fr_FR.UTF-8" refer to incompatible locales. To me initdb is wrong when coming up with the less precise "fr" instead of "fr-FR". I suggest the attached patch to call uloc_getDefault() instead of the current code that somehow leaves out the country/region component. Best regards, --=20 Daniel V=E9rit=E9 https://postgresql.verite.pro/ Twitter: @DanielVerite ------------=_1685118275-17172-59 Content-Type: text/x-patch; name="initdb-uloc_getdefault.diff" Content-Disposition: attachment; filename="initdb-uloc_getdefault.diff" Content-Transfer-Encoding: 7bit diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 31156e863b..09a5c98cc0 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -2354,42 +2354,13 @@ icu_validate_locale(const char *loc_str) } /* - * Determine default ICU locale by opening the default collator and reading - * its locale. - * - * NB: The default collator (opened using NULL) is different from the collator - * for the root locale (opened with "", "und", or "root"). The former depends - * on the environment (useful at initdb time) and the latter does not. + * Determine the default ICU locale */ static char * default_icu_locale(void) { #ifdef USE_ICU - UCollator *collator; - UErrorCode status; - const char *valid_locale; - char *default_locale; - - status = U_ZERO_ERROR; - collator = ucol_open(NULL, &status); - if (U_FAILURE(status)) - pg_fatal("could not open collator for default locale: %s", - u_errorName(status)); - - status = U_ZERO_ERROR; - valid_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE, - &status); - if (U_FAILURE(status)) - { - ucol_close(collator); - pg_fatal("could not determine default ICU locale"); - } - - default_locale = pg_strdup(valid_locale); - - ucol_close(collator); - - return default_locale; + return pg_strdup(uloc_getDefault()); #else pg_fatal("ICU is not supported in this build"); #endif ------------=_1685118275-17172-59--