From 93ffadb446e55256667aeaae72e003ab61d79dfc Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Sat, 31 Oct 2026 20:34:20 -0400 Subject: [PATCH] Don't inherit ICU rules from template for non-ICU databases Commit 2d819a08a1 dropped the provider check, so CREATE DATABASE with another provider failed after initdb --icu-rules. Reported-by: Heikki Linnakangas 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 | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 7e3fc59eafd..e3a09b33214 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -1096,7 +1096,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 c6f34fea84b..e40fa815da4 100644 --- a/src/test/icu/t/010_database.pl +++ b/src/test/icu/t/010_database.pl @@ -81,4 +81,33 @@ like( qr/ERROR: new locale provider \(builtin\) does not match locale provider of the template database \(icu\)/, "locale provider must match template: error message"); +# ICU rules set by initdb are inherited from template0 only by ICU databases +my $node2 = PostgreSQL::Test::Cluster->new('node2'); +$node2->init( + extra => [ + '--locale-provider=icu', '--icu-locale=en', + '--icu-rules=&a < g', '--encoding=UTF8' + ]); +$node2->start; + +$node2->safe_psql('postgres', + q{CREATE DATABASE dbbuiltin LOCALE_PROVIDER builtin LOCALE 'C' TEMPLATE template0} +); +is( $node2->safe_psql( + 'postgres', + q{SELECT daticurules IS NULL FROM pg_database WHERE datname = 'dbbuiltin'} + ), + qq(t), + 'non-ICU database does 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')) t(x) ORDER BY x}), + qq(a +g +b), + 'ICU database inherits ICU rules from template0'); + done_testing(); -- 2.37.1 (Apple Git-137.1)