postgresql_16:9.6.10.4 Limitations
PostgreSQL 16 > Appendixes > Additional Supplied Modules and Extensions > citext — a case-insensitive character string type > Limitations
citext's case-folding behavior depends on theLC_CTYPEsetting of your database. How it compares values is therefore determined when the database is created. It is not truly case-insensitive in the terms defined by the Unicode standard. Effectively, what this means is that, as long as you're happy with your collation, you should be happy withcitext's comparisons. But if you have data in different languages stored in your database, users of one language may find their query results are not as expected if the collation is for another language.- As of PostgreSQL 9.1, you can attach a
COLLATEspecification tocitextcolumns or data values. Currently,citextoperators will honor a non-defaultCOLLATEspecification while comparing case-folded strings, but the initial folding to lower case is always done according to the database'sLC_CTYPEsetting (that is, as thoughCOLLATE "default"were given). This may be changed in a future release so that both steps follow the inputCOLLATEspecification. citextis not as efficient astextbecause the operator functions and the B-tree comparison functions must make copies of the data and convert it to lower case for comparisons. Also, onlytextcan support B-Tree deduplication. However,citextis slightly more efficient than usinglowerto get case-insensitive matching.citextdoesn't help much if you need data to compare case-sensitively in some contexts and case-insensitively in other contexts. The standard answer is to use thetexttype and manually use thelowerfunction when you need to compare case-insensitively; this works all right if case-insensitive comparison is needed only infrequently. If you need case-insensitive behavior most of the time and case-sensitive infrequently, consider storing the data ascitextand explicitly casting the column totextwhen you want case-sensitive comparison. In either situation, you will need two indexes if you want both types of searches to be fast.- The schema containing the
citextoperators must be in the currentsearch_path(typicallypublic); if it is not, the normal case-sensitivetextoperators will be invoked instead. - The approach of lower-casing strings for comparison does not handle some Unicode special cases correctly, for example when one upper-case letter has two lower-case letter equivalents. Unicode distinguishes between *case mapping* and *case folding* for this reason. Use nondeterministic collations instead of
citextto handle that correctly.