Improve CREATE DATABASE error message for invalid libc locale.
authorJeff Davis <[email protected]>
Fri, 6 Jun 2025 22:28:51 +0000 (15:28 -0700)
committerJeff Davis <[email protected]>
Fri, 6 Jun 2025 22:28:51 +0000 (15:28 -0700)
Discussion: https://postgr.es/m/73959a14-267b-49c1-8293-291b175682cb@manitou-mail.org
Reviewed-by: Daniel Verite <[email protected]>
src/backend/commands/dbcommands.c

index 5fbbcdaabb1d20edcaa15e162a3dc9bcd9e76391..c95eb94501671dc42176c0347417cec8db095a55 100644 (file)
@@ -1065,16 +1065,41 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
 
    /* Check that the chosen locales are valid, and get canonical spellings */
    if (!check_locale(LC_COLLATE, dbcollate, &canonname))
-       ereport(ERROR,
-               (errcode(ERRCODE_WRONG_OBJECT_TYPE),
-                errmsg("invalid LC_COLLATE locale name: \"%s\"", dbcollate),
-                errhint("If the locale name is specific to ICU, use ICU_LOCALE.")));
+   {
+       if (dblocprovider == COLLPROVIDER_BUILTIN)
+           ereport(ERROR,
+                   (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                    errmsg("invalid LC_COLLATE locale name: \"%s\"", dbcollate),
+                    errhint("If the locale name is specific to the builtin provider, use BUILTIN_LOCALE.")));
+       else if (dblocprovider == COLLPROVIDER_ICU)
+           ereport(ERROR,
+                   (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                    errmsg("invalid LC_COLLATE locale name: \"%s\"", dbcollate),
+                    errhint("If the locale name is specific to the ICU provider, use ICU_LOCALE.")));
+       else
+           ereport(ERROR,
+                   (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                    errmsg("invalid LC_COLLATE locale name: \"%s\"", dbcollate)));
+   }
    dbcollate = canonname;
    if (!check_locale(LC_CTYPE, dbctype, &canonname))
-       ereport(ERROR,
-               (errcode(ERRCODE_WRONG_OBJECT_TYPE),
-                errmsg("invalid LC_CTYPE locale name: \"%s\"", dbctype),
-                errhint("If the locale name is specific to ICU, use ICU_LOCALE.")));
+   {
+       if (dblocprovider == COLLPROVIDER_BUILTIN)
+           ereport(ERROR,
+                   (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                    errmsg("invalid LC_CTYPE locale name: \"%s\"", dbctype),
+                    errhint("If the locale name is specific to the builtin provider, use BUILTIN_LOCALE.")));
+       else if (dblocprovider == COLLPROVIDER_ICU)
+           ereport(ERROR,
+                   (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                    errmsg("invalid LC_CTYPE locale name: \"%s\"", dbctype),
+                    errhint("If the locale name is specific to the ICU provider, use ICU_LOCALE.")));
+       else
+           ereport(ERROR,
+                   (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                    errmsg("invalid LC_CTYPE locale name: \"%s\"", dbctype)));
+   }
+
    dbctype = canonname;
 
    check_encoding_locale_matches(encoding, dbcollate, dbctype);