Types, Constraints & Database Objects

Text Types, Collations, and Encoding

Text correctness spans character encoding, length semantics, normalization, and collation; comparison rules affect ordering, equality, indexes, and whether a unique constraint rejects two spellings.
  • Unicode is a character repertoire, while UTF-8 is an encoding.
  • CHAR, VARCHAR, and large text differ in constraints more than meaning.
  • A collation defines comparison and sort behavior.
  • Canonical-equivalent Unicode can have different code sequences.
  • Uniqueness inherits comparison semantics.
  • Changing collation can require rebuilding indexes.
Comparison policy and consequence
PolicyMay compare equalUnique-key consequence
Binary/code-unitRésumé only to identical encodingCase/accent variants coexist
Case-insensitiveSKU-7, sku-7Only one spelling can be inserted
Case- and accent-insensitiveresume, résuméBoth collapse to one key
Normalized application keyCanonical-equivalent sequencesStable only if every write uses the same normalization
CREATE TABLE product_aliases (
  alias_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  product_id BIGINT NOT NULL REFERENCES products(product_id),
  display_name TEXT NOT NULL,
  search_name TEXT COLLATE "und-x-icu" NOT NULL,
  UNIQUE (search_name)
);

The added product_aliases object separates preserved display text from an identity/search key. The shown collations illustrate vendor syntax, not a portable promise: test actual case, accent, punctuation, normalization, and language behavior for the chosen collation.