postgres.git / summary / log / commit / refs
commit ede2e7e47c3b0aa384b3f67f3fe3584ca0c57009
Author: Jeff Davis <jdavis@postgresql.org>
Date: Thu Nov 19 04:02:38 2026 +0000
Fix CREATE DATABASE when template0 has ICU rules.
Most fields, when not specified by the CREATE DATABASE command, are
simply copied from the template. But when the template has ICU rules,
and the new database uses a different provider (which is only possible
with template0), then we should ignore the ICU rules from the
template. But after commit 2d819a08a1, it tried to copy the ICU rules,
and the command resulted in an error.
This commit restores the prior behavior, which ignores the ICU rules
from the template if the new provider is not ICU.
Author: shihao zhong <zhong950419@gmail.com>
Reported-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/c97d5993-5d9f-4f75-97f1-7e69643e37c0@iki.fi
Backpatch-through: 17
src/backend/commands/dbcommands.c | 2 +-
src/test/icu/t/010_database.pl | 44 +++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 5eb6caffe6d..364c747a330 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -1054,7 +1054,7 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
dblocprovider = src_locprovider;
if (dblocale == NULL && dblocprovider == src_locprovider)
dblocale = src_locale;
- if (dbicurules == NULL)
+ if (dbicurules == NULL && dblocprovider == COLLPROVIDER_ICU)
dbicurules = src_icurules;
/* Some encodings are client only */
diff --git a/src/test/icu/t/010_database.pl b/src/test/icu/t/010_database.pl
index 6ab8b154319..024c2de244b 100644
--- a/src/test/icu/t/010_database.pl
+++ b/src/test/icu/t/010_database.pl
@@ -81,4 +81,48 @@ like(
qr/ERROR: new locale provider \(builtin\) does not match locale provider of the template database \(icu\)/,
"locale provider must match template: error message");
+
+# When template0 has ICU rules (initdb --icu-rules), only databases
+# using the ICU provider inherit them. Other providers must be usable
+# without specifying ICU rules.
+my $node2 = PostgreSQL::Test::Cluster->new('node2');
+$node2->init(
+ extra => [
+ '--locale=C', '--encoding=UTF8',
+ '--locale-provider=icu', '--icu-locale=en',
+ '--icu-rules=&a < g',
+ ]);
+$node2->start;
+
+is( $node2->psql(
+ 'postgres',
+ q{CREATE DATABASE dbbuiltin LOCALE_PROVIDER builtin BUILTIN_LOCALE 'C' TEMPLATE template0}
+ ),
+ 0,
+ "builtin provider database can be created when template0 has ICU rules");
+is( $node2->psql(
+ 'postgres',
+ q{CREATE DATABASE dblibc LOCALE_PROVIDER libc LOCALE 'C' TEMPLATE template0}
+ ),
+ 0,
+ "libc provider database can be created when template0 has ICU rules");
+is( $node2->safe_psql(
+ 'postgres',
+ q{SELECT datname, daticurules IS NULL FROM pg_database
+ WHERE datname IN ('dbbuiltin', 'dblibc') ORDER BY datname}),
+ qq(dbbuiltin|t
+dblibc|t),
+ "non-ICU databases do not inherit ICU rules from template0");
+
+$node2->safe_psql('postgres',
+ q{CREATE DATABASE dbicurules TEMPLATE template0});
+is( $node2->safe_psql(
+ 'dbicurules',
+ q{SELECT x FROM (VALUES ('a'), ('b'), ('g')) AS v(x) ORDER BY x}),
+ qq(a
+g
+b),
+ "ICU database inherits ICU rules from template0");
+
+
done_testing();
[parent: 9107706245e2]