Preserve the value; choose the comparison
The users table stores email as citext, with a separate UNIQUE constraint. Three casings of user1@example.com select the same user_0001 record. The literal comparison preserves Alice@Example.com while returning f for the plain-text equality and t for citext equality here. Neither the type nor case folding is a universal rule for every application's identity policy.
username is plain text: equality to USER_0002 fails, while LOWER on both operands finds user_0002. An expression index can support an appropriate LOWER predicate, but an index's presence is not a guarantee about the actual plan. Index tuning is reference, not measured in this lesson.
Transform both sides consistently
The baseline already applies LOWER, so the changed query adds only accent removal. The original display name is still accented in the result. unaccent does not lowercase by itself: müller becomes muller and MÜLLER becomes MULLER. Locale rules affect case folding; citext and LOWER should not be described as a complete solution to every Unicode or language requirement.
Use a collation that actually exists
The inspected database uses C for collation and character classification. Its C/POSIX collations are deterministic libc collations. The provided literal sort demonstrates A, B, a, b under explicit COLLATE "C". This is an ASCII example, not Czech alphabetical ordering. ICU and nondeterministic collations are reference for environments that provide them; this lab does not attempt to run an absent cs-CZ-x-icu collation.
Did you know?
The unaccent rules can expand a ligature into multiple characters, such as Æ to AE. The function is more than deleting accent marks, and it does not imply case folding. PostgreSQL documentation.
Key concepts
citext
An extension type offering locale-dependent case-insensitive comparisons while preserving stored spelling. The existing email UNIQUE constraint uses citext equality. Explicitly casting to text can select text comparisons instead; the type is not universally the best choice for every Unicode policy.
unaccent()
The installed unaccent extension maps characters using its rules, including removing diacritics or expanding ligatures. It does not itself lowercase. Applying it in a SELECT does not replace the stored display name.