]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Allow setting the collation strength in ICU tailoring rules
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 18 Mar 2026 07:54:35 +0000 (08:54 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 18 Mar 2026 07:58:47 +0000 (08:58 +0100)
There was a bug that if you created an ICU collation with tailoring
rules, any strength specification inside the rules was ignored.  This
was because we called ucol_openRules() with UCOL_DEFAULT_STRENGTH for
the strength argument, which overrides the strength.  This was because
of faulty guidance in the ICU documentation, which has since been
fixed.  The correct invocation is to use UCOL_DEFAULT for the strength
argument.

This fixes bug #18771 and bug #19425.

Author: Daniel Verite <daniel@manitou-mail.org>
Reported-by: Ruben Ruiz <ruben.ruizcuadrado@gmail.com>
Reported-by: dorian.752@live.fr
Reported-by: Todd Lang <Todd.Lang@D2L.com>
Discussion: https://www.postgresql.org/message-id/flat/YT2PPF959236618377A072745A280E278F4BE1DA@YT2PPF959236618.CANPRD01.PROD.OUTLOOK.COM
Discussion: https://www.postgresql.org/message-id/flat/18771-98bb23e455b0f367@postgresql.org
Discussion: https://www.postgresql.org/message-id/flat/19425-58915e19dacd4f40%40postgresql.org

src/backend/utils/adt/pg_locale_icu.c
src/test/regress/expected/collate.icu.utf8.out
src/test/regress/sql/collate.icu.utf8.sql

index 352b4c3885fb63ab24fe78f4e2bcd4785fec435d..5ad05fcd01695109fca329832b469ce3254b4827 100644 (file)
@@ -587,7 +587,7 @@ make_icu_collator(const char *iculocstr, const char *icurules)
 
                status = U_ZERO_ERROR;
                collator_all_rules = ucol_openRules(all_rules, u_strlen(all_rules),
-                                                                                       UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH,
+                                                                                       UCOL_DEFAULT, UCOL_DEFAULT,
                                                                                        NULL, &status);
                if (U_FAILURE(status))
                {
index 1325e1238777c04f597a0a2428b34b9a22de4efe..d170e7da066b56db215ee51b710345b1a8812c22 100644 (file)
@@ -1297,6 +1297,14 @@ DROP TABLE test7;
 CREATE COLLATION testcoll_rulesx (provider = icu, locale = '', rules = '!!wrong!!');
 NOTICE:  using standard form "und" for ICU locale ""
 ERROR:  could not open collator for locale "und" with rules "!!wrong!!": U_INVALID_FORMAT_ERROR
+-- strength specified in the rules
+CREATE COLLATION strength_in_rule (provider = icu, locale = 'und', deterministic = false, rules = '[strength 1]');
+SELECT 'a' = 'à' COLLATE strength_in_rule;  -- true because of the rule
+ ?column? 
+----------
+ t
+(1 row)
+
 -- nondeterministic collations
 CREATE COLLATION ctest_det (provider = icu, locale = '', deterministic = true);
 NOTICE:  using standard form "und" for ICU locale ""
index b6c54503d219a28750305c4914420f1b24993f25..8f0f973f5fae1bb0420154d57329876a7dc809d5 100644 (file)
@@ -513,6 +513,10 @@ DROP TABLE test7;
 
 CREATE COLLATION testcoll_rulesx (provider = icu, locale = '', rules = '!!wrong!!');
 
+-- strength specified in the rules
+CREATE COLLATION strength_in_rule (provider = icu, locale = 'und', deterministic = false, rules = '[strength 1]');
+SELECT 'a' = 'à' COLLATE strength_in_rule;  -- true because of the rule
+
 
 -- nondeterministic collations