10000 Improve CREATE DATABASE error message for invalid libc locale. · theory/postgres@5b40fea · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b40fea

Browse files
committed
Improve CREATE DATABASE error message for invalid libc locale.
Discussion: https://postgr.es/m/73959a14-267b-49c1-8293-291b175682cb@manitou-mail.org Reviewed-by: Daniel Verite <daniel@manitou-mail.org>
1 parent a31767f commit 5b40fea

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/backend/commands/dbcommands.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,16 +1065,41 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
10651065

10661066
/* Check that the chosen locales are valid, and get canonical spellings */
10671067
if (!check_locale(LC_COLLATE, dbcollate, &canonname))
1068-
ereport(ERROR,
1069-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1070-
errmsg("invalid LC_COLLATE locale name: \"%s\"", dbcollate),
1071-
errhint("If the locale name is specific to ICU, use ICU_LOCALE.")));
1068+
{
1069+
if (dblocprovider == COLLPROVIDER_BUILTIN)
1070+
ereport(ERROR,
1071+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1072+
errmsg("invalid LC_COLLATE locale name: \"%s\"", dbcollate),
1073+
errhint("If the locale name is specific to the builtin provider, use BUILTIN_LOCALE.")));
1074+
else if (dblocprovider == COLLPROVIDER_ICU)
1075+
ereport(ERROR,
1076+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1077+
errmsg("invalid LC_COLLATE locale name: \"%s\"", dbcollate),
1078+
errhint("If the locale name is specific to the ICU provider, use ICU_LOCALE.")));
1079+
else
1080+
ereport(ERROR,
1081+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1082+
errmsg("invalid LC_COLLATE locale name: \"%s\"", dbcollate)));
1083+
}
10721084
dbcollate = canonname;
10731085
if (!check_locale(LC_CTYPE, dbctype, &canonname))
1074-
ereport(ERROR,
1075-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1076-
errmsg("invalid LC_CTYPE locale name: \"%s\"", dbctype),
1077-
errhint("If the locale name is specific to ICU, use ICU_LOCALE.")));
1086+
{
1087+
if (dblocprovider == COLLPROVIDER_BUILTIN)
1088+
ereport(ERROR,
1089+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1090+
errmsg("invalid LC_CTYPE locale name: \"%s\"", dbctype),
1091+
errhint("If the locale name is specific to the builtin provider, use BUILTIN_LOCALE.")));
1092+
else if (dblocprovider == COLLPROVIDER_ICU)
1093+
ereport(ERROR,
1094+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1095+
errmsg("invalid LC_CTYPE locale name: \"%s\"", dbctype),
1096+
errhint("If the locale name is specific to the ICU provider, use ICU_LOCALE.")));
1097+
else
1098+
ereport(ERROR,
1099+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1100+
errmsg("invalid LC_CTYPE locale name: \"%s\"", dbctype)));
1101+
}
1102+
10781103
dbctype = canonname;
10791104

10801105
check_encoding_locale_matches(encoding, dbcollate, dbctype);

0 commit comments

Comments
 (0)
0