Skip to content

Commit 865b52a

Browse files
committed
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 ab7032b commit 865b52a

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
@@ -907,10 +907,6 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
907907
errmsg("unrecognized locale provider: %s",
908908
locproviderstr)));
909909
}
910-
if (diculocale && dblocprovider != COLLPROVIDER_ICU)
911-
ereport(ERROR,
912-
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
913-
errmsg("ICU locale cannot be specified unless locale provider is ICU")));
914910
if (distemplate && distemplate->arg)
915911
dbistemplate = defGetBoolean(distemplate);
916912
if (dallowconnections && dallowconnections->arg)
@@ -1050,6 +1046,13 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
10501046

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

10541057
/*
10551058
* 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)