From 2991ac5fc9b3904ca4582be6d323497d7c3d17c9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 26 Mar 2020 08:14:00 +0100 Subject: Add SQL functions for Unicode normalization This adds SQL expressions NORMALIZE() and IS NORMALIZED to convert and check Unicode normal forms, per SQL standard. To support fast IS NORMALIZED tests, we pull in a new data file DerivedNormalizationProps.txt from Unicode and build a lookup table from that, using techniques similar to ones already used for other Unicode data. make update-unicode will keep it up to date. We only build and use these tables for the NFC and NFKC forms, because they are too big for NFD and NFKD and the improvement is not significant enough there. Reviewed-by: Daniel Verite Reviewed-by: Andreas Karlsson Discussion: https://www.postgresql.org/message-id/flat/c1909f27-c269-2ed9-12f8-3ab72c8caf7a@2ndquadrant.com --- doc/src/sgml/charset.sgml | 10 ++++++++++ doc/src/sgml/func.sgml | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/charset.sgml b/doc/src/sgml/charset.sgml index 20cdfabd7bf..b6023fa459e 100644 --- a/doc/src/sgml/charset.sgml +++ b/doc/src/sgml/charset.sgml @@ -934,6 +934,16 @@ CREATE COLLATION ignore_accents (provider = icu, locale = 'und-u-ks-level1-kc-tr such as pattern matching operations. Therefore, they should be used only in cases where they are specifically wanted. + + + + To deal with text in different Unicode normalization forms, it is also + an option to use the functions/expressions + normalize and is normalized to + preprocess or check the strings, instead of using nondeterministic + collations. There are different trade-offs for each approach. + + diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index cbfd2a762e4..a329f61f339 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1560,6 +1560,30 @@ Value: 42 + + + + normalized + + + Unicode normalization + + string is not form normalized + + boolean + + Checks whether the string is in the specified Unicode normalization + form. The optional parameter specifies the form: + NFC (default), NFD, + NFKC, NFKD. This expression can + only be used if the server encoding is UTF8. Note + that checking for normalization using this expression is often faster + than normalizing possibly already normalized strings. + + U&'\0061\0308bc' IS NFD NORMALIZED + true + + @@ -1610,6 +1634,30 @@ tom + + + + normalize + + + Unicode normalization + + normalize(string text + , form ) + + text + + Converts the string in the first argument to the specified Unicode + normalization form. The optional second argument specifies the form + as an identifier: NFC (default), + NFD, NFKC, + NFKD. This function can only be used if the server + encoding is UTF8. + + normalize(U&'\0061\0308bc', NFC) + U&'\00E4bc' + + -- cgit v1.2.3