doc: Add more ICU rules examples
authorPeter Eisentraut
Wed, 23 Aug 2023 09:23:42 +0000 (11:23 +0200)
committerPeter Eisentraut
Wed, 23 Aug 2023 09:24:43 +0000 (11:24 +0200)
In particular, add an example EBCDIC collation.

Author: Daniel Verite 
Discussion: https://www.postgresql.org/message-id/flat/35cc1684-e516-4a01-a256-351632d47066@manitou-mail.org

doc/src/sgml/charset.sgml
doc/src/sgml/ref/create_collation.sgml
doc/src/sgml/ref/create_database.sgml

index dd092fddd6108f8ada9ee2e96f3dfc5738656e48..25febcac4c08e8173781584e6c4805a76bfd9482 100644 (file)
@@ -1481,7 +1481,7 @@ SELECT 'x-y' = 'x_y' COLLATE level4; -- false
    
 
    
-    Examples
+    <span class="marked">Collation Settings </span>Examples
 
      
       
@@ -1530,6 +1530,62 @@ SELECT 'x-y' = 'x_y' COLLATE level4; -- false
      
    
 
+   
+    ICU Tailoring Rules
+
+    
+     If the options provided by the collation settings shown above are not
+     sufficient, the order of collation elements can be changed with tailoring
+     rules, whose syntax is detailed at 
+     url="https://unicode-org.github.io/icu/userguide/collation/customization/">.
+    
+
+    
+     This small example creates a collation based on the root locale with a
+     tailoring rule:
+
+
+
+     With this rule, the letter W is sorted after
+     V, but is treated as a secondary difference similar to an
+     accent.  Rules like this are contained in the locale definitions of some
+     languages.  (Of course, if a locale definition already contains the
+     desired rules, then they don't need to be specified again explicitly.)
+    
+
+    
+     Here is a more complex example.  The following statement sets up a
+     collation named ebcdic with rules to sort US-ASCII
+     characters in the order of the EBCDIC encoding.
+
+
+
+rules = $$
+& ' ' < '.' < '<' < '(' < '+' < \|
+< '&' < '!' < '$' < '*' < ')' < ';'
+< '-' < '/' < ',' < '%' < '_' < '>' < '?'
+< '`' < ':' < '#' < '@' < \' < '=' < '"'
+<*a-r < '~' <*s-z < '^' < '[' < ']'
+< '{' <*A-I < '}' <*J-R < '\' <*S-Z <*0-9
+$$);]]>
+
+SELECT c
+FROM (VALUES ('a'), ('b'), ('A'), ('B'), ('1'), ('2'), ('!'), ('^')) AS x(c)
+ORDER BY c COLLATE ebcdic;
+ c
+---
+ !
+ a
+ b
+ ^
+ A
+ B
+ 1
+ 2
+
+    
+   
+
    
     External References for ICU
 
index b86a9bbb9cebab91f14082516a17fea6fdd6005a..5cf9777764b701a54541607dfec72b4be0ee2346 100644 (file)
@@ -165,9 +165,8 @@ CREATE COLLATION [ IF NOT EXISTS ] name FROM 
      
       
        Specifies additional collation rules to customize the behavior of the
-       collation.  This is supported for ICU only.  See 
-       url="https://unicode-org.github.io/icu/userguide/collation/customization/"/>
-       for details on the syntax.
+       collation.  This is supported for ICU only.  See 
+       linkend="icu-tailoring-rules"/> for details.
       
      
     
@@ -257,12 +256,8 @@ CREATE COLLATION german_phonebook (provider = icu, locale = 'de-u-co-phonebk');
 
 
 
-   With this rule, the letter W is sorted after
-   V, but is treated as a secondary difference similar to an
-   accent.  Rules like this are contained in the locale definitions of some
-   languages.  (Of course, if a locale definition already contains the desired
-   rules, then they don't need to be specified again explicitly.)  See the ICU
-   documentation for further details and examples on the rules syntax.
+   See  for further details and examples
+   on the rules syntax.
   
 
   
index b2c8aef1ad2204040bb00a84476fb004ad7de9fa..ce7317f81ba6d4bc2b357a4bf1729d3f9554af2c 100644 (file)
@@ -232,9 +232,7 @@ CREATE DATABASE name
        
         Specifies additional collation rules to customize the behavior of the
         default collation of this database.  This is supported for ICU only.
-        See 
-        url="https://unicode-org.github.io/icu/userguide/collation/customization/"/>
-        for details on the syntax.
+        See  for details.