⚠️ This post links to an external website. ⚠️
The PostgreSQL
citexttype (docs here) is a good choice for lots of user-facing text.It stores the text with the case given, but for comparisons it ignores case.
You probably want searches to be case insensitive; eg, searching for "alex" should match "Alex".
citextmeans you don't have to remember to convert the search term and column value to lowercase when searching.Also, if you want to sort names alphabetically, you probably want
Bananato come afterapple, even though upper case Latin characters have smaller codepoint values than lower case ones (see the decimal set inman ascii). Since sorting involves comparison,citexttakes care of this.And if you have a unique index, you probably don't want to allow both
foo@example.comandFoo@example.com. Again, since unique indexes involve comparison,citextmeans these values conflict.Note that
citextis an extension; you have toCREATE EXTENSION IF NOT EXISTS citextin order to use it.Here are a few quick demos.
continue reading on nathanmlong.com
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.