Fix assertion failure in CREATE DATABASE
authorPeter Eisentraut <[email protected]>
Mon, 22 Aug 2022 13:31:50 +0000 (15:31 +0200)
committerPeter Eisentraut <[email protected]>
Mon, 22 Aug 2022 13:38:41 +0000 (15:38 +0200)
An assertion would fail when creating a database with libc locale
provider from a template database with icu locale provider.

Reported-by: Marina Polyakova <[email protected]>
Reviewed-by: Julien Rouhaud <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/f385ba25e7f8be427b8c582e5cca7d79%40postgrespro.ru#515a31c5429d6d37ad1d5c9d66962a1e

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

index b31a30550b025d48ba3cc250dc4c15f41f9a80be..883f381f3453142790f728a3725586cebe2e2f20 100644 (file)
@@ -1012,10 +1012,10 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
                dbcollate = src_collate;
        if (dbctype == NULL)
                dbctype = src_ctype;
-       if (dbiculocale == NULL)
-               dbiculocale = src_iculocale;
        if (dblocprovider == '\0')
                dblocprovider = src_locprovider;
+       if (dbiculocale == NULL && dblocprovider == COLLPROVIDER_ICU)
+               dbiculocale = src_iculocale;
 
        /* Some encodings are client only */
        if (!PG_VALID_BE_ENCODING(encoding))
index 78733f64d2517f42aff25ffe0ccdacd81ddb4eb2..e91c1d013d08d8bd1e3a92f2aba958c5c7713ca6 100644 (file)
@@ -49,6 +49,15 @@ if ($ENV{with_icu} eq 'yes')
                        '--icu-locale=@colNumeric=lower', 'foobarX'
                ],
                'fails for invalid ICU locale');
+
+       # additional node, which uses the icu provider
+       my $node2 = PostgreSQL::Test::Cluster->new('icu');
+       $node2->init(extra => ['--locale-provider=icu', '--icu-locale=en']);
+       $node2->start;
+
+       $node2->command_ok(
+               [ 'createdb', '-T', 'template0', '--locale-provider=libc', 'foobar55' ],
+               'create database with libc provider from template database with icu provider');
 }
 else
 {