Improve ICU option handling in CREATE DATABASE
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 21 Sep 2022 14:28:40 +0000 (10:28 -0400)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 21 Sep 2022 14:41:36 +0000 (10:41 -0400)
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

src/backend/commands/dbcommands.c
src/bin/scripts/t/020_createdb.pl

index 308dc93f63fc5660797c0e9367fdc4775d16b4ac..e0753c1badcc299e2bac45f3bdd2f23f59d70cbc 100644 (file)
@@ -908,10 +908,6 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
                     errmsg("unrecognized locale provider: %s",
                            locproviderstr)));
    }
-   if (diculocale && dblocprovider != COLLPROVIDER_ICU)
-       ereport(ERROR,
-               (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-                errmsg("ICU locale cannot be specified unless locale provider is ICU")));
    if (distemplate && distemplate->arg)
        dbistemplate = defGetBoolean(distemplate);
    if (dallowconnections && dallowconnections->arg)
@@ -1051,6 +1047,13 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
 
        check_icu_locale(dbiculocale);
    }
+   else
+   {
+       if (dbiculocale)
+           ereport(ERROR,
+                   (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+                    errmsg("ICU locale cannot be specified unless locale provider is ICU")));
+   }
 
    /*
     * Check that the new encoding and locale settings match the source
index b87d8fc63b5246b02bcd4499aae815269b60df7c..8ed8628db11c1410db4987f11250535bfb1aa008 100644 (file)
@@ -71,6 +71,10 @@ if ($ENV{with_icu} eq 'yes')
    $node2->command_ok(
        [ 'createdb', '-T', 'template0', '--locale-provider=libc', 'foobar55' ],
        'create database with libc provider from template database with icu provider');
+
+   $node2->command_ok(
+       [ 'createdb', '-T', 'template0', '--icu-locale', 'en-US', 'foobar56' ],
+       'create database with icu locale from template database with icu provider');
 }
 else
 {