Skip to content

Commit cce7135

Browse files
peterepull[bot]
authored andcommitted
Improve ICU option handling in CREATE DATABASE
We check that the ICU locale is only specified if the ICU locale provider is selected. But we did that too early. We need to wait until we load the settings of the template database, since that could also set what the locale provider is. Reported-by: Marina Polyakova <m.polyakova@postgrespro.ru> Discussion: https://www.postgresql.org/message-id/9ba4cd1ea6ed6b7b15c0ff15e6f540cd@postgrespro.ru
1 parent 8c4ca69 commit cce7135

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/backend/commands/dbcommands.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,6 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
908908
errmsg("unrecognized locale provider: %s",
909909
locproviderstr)));
910910
}
911-
if (diculocale && dblocprovider != COLLPROVIDER_ICU)
912-
ereport(ERROR,
913-
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
914-
errmsg("ICU locale cannot be specified unless locale provider is ICU")));
915911
if (distemplate && distemplate->arg)
916912
dbistemplate = defGetBoolean(distemplate);
917913
if (dallowconnections && dallowconnections->arg)
@@ -1051,6 +1047,13 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
10511047

10521048
check_icu_locale(dbiculocale);
10531049
}
1050+
else
1051+
{
1052+
if (dbiculocale)
1053+
ereport(ERROR,
1054+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1055+
errmsg("ICU locale cannot be specified unless locale provider is ICU")));
1056+
}
10541057

10551058
/*
10561059
* Check that the new encoding and locale settings match the source

src/bin/scripts/t/020_createdb.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
$node2->command_ok(
7272
[ 'createdb', '-T', 'template0', '--locale-provider=libc', 'foobar55' ],
7373
'create database with libc provider from template database with icu provider');
74+
75+
$node2->command_ok(
76+
[ 'createdb', '-T', 'template0', '--icu-locale', 'en-US', 'foobar56' ],
77+
'create database with icu locale from template database with icu provider');
7478
}
7579
else
7680
{

0 commit comments

Comments
 (0)