What is the recommended collation for a PostgreSQL unique e-mail column?

Most places recommend for unique e-mail indexes using either a lower(email) index, or a datatype citext.

But the manual for citext suggests using a collation for all cases instead of citext now:

Consider using nondeterministic collations instead of this module.

So, currently, what is the recommended way to treat a unique e-mail column in PostgreSQL?

Index on lower()? citext still? Or if collation, which one exactly?

if collate, which one exactly?

Whichever one you prefer – it’s not necessarily about picking a specific collation out of the built-in list, but configuring one that way. As demonstrated in the doc:
demo at db<>fiddle

CREATE COLLATION case_insensitive (
  provider = icu, 
  locale = 'und-u-ks-level2', --undefined(root,generic), but you can pick a language
  deterministic = false);
SELECT 'a' = 'A' COLLATE case_insensitive; -- true

If you’re asking about which locale is recommended for the case-insensitive collation, I’d say that’s the generic one above but ultimately it won’t matter. Others mainly differ in how they sort things, and unless specifically configured for the purpose, I don’t think they’ll disagree on equality you want for unique.

I assumed you’re asking which particular collation is the recommendation, in which case there’s no such thing – a standard installation doesn’t ship with a built-in case-insensitive collation out of the box. Japanese, Arabic and Chinese are examples of “case-insensitive” languages (characters don’t have upper/lower variants) but collations based on them aren’t themselves case-insensitive when they deal with other alphabets.

If you’re asking about performance, in this test on 150k 90% unique random samples as well as another one I ran on 10M, the expression index using lower() on a text column with collate "C" tends to perform best, followed closely by a regular index on the text column using the case-insensitive icu collation. citext stays way behind.


My point is that the character set for email is not open to interpretation. email rfc uses ascii, with several chars removed, it doesn’t care about internationalization standards.

There’s more than one “email RFC” so you could argue that even the meaning of “email RFC” is open to interpretation. Also, it is not “ASCII-only, with several chars removed”, or at least it hasn’t been for a while now. Here’s a relatively old thread discussing these topics, linking a nice example at Wikipedia:

The example addresses below would not be handled by RRFC 5322 based servers, but are permitted by RFC 6530. Servers compliant with this will be able to handle these:

  • Latin alphabet with diacritics: Pelé@example.com
  • Greek alphabet: δοκιμή@παράδειγμα.δοκιμή
  • Traditional Chinese characters: 我買@屋企.香港
  • Japanese characters: 二ノ宮@黒川.日本
  • Cyrillic characters: медведь@с-балалайкой.рф
  • Devanagari characters: संपर्क@डाटामेल.भारत

I feel like I need to draw a line: character sets are about encoding. Collations you asked about are for sorting and equality, and most work with all encoding options. You can tell by checking pg_collation.collencoding = -1:

collencoding int4
Encoding in which the collation is applicable, or -1 if it works for any encoding

In case you wanted to ask about email address validation and normalisation through a column constraint, that’s a slightly different question.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật