Part 9: Character Data Types: CHAR, VARCHAR, TEXT & Collation
Storing textual data requires understanding string length constraints, memory padding, and character encodings.
1. String Types Comparison
CHAR(n): Fixed length. If you store'CA'inCHAR(5), the database pads it with 3 spaces ('CA '). Ideal for fixed codes (e.g. ISO Country CodesCHAR(2)).VARCHAR(n): Variable length with a maximum limitn. Stores only the actual characters plus 1–2 length bytes. Ideal for names, emails, titles.TEXT: Unlimited variable length (up to 1GB in Postgres). Ideal for blog articles, descriptions, comments.
2. Character Sets & Collation
- Character Set (e.g.
utf8mb4): Dictates which characters can be stored (including full emoji support). - Collation (e.g.
utf8mb4_unicode_ci): Dictates how strings are compared and sorted: _ci: Case-Insensitive ('Apple'equals'apple')._cs: Case-Sensitive ('Apple'does NOT equal'apple').
Key Takeaways
- Use
CHAR(n)for fixed-length codes. - Use
VARCHAR(n)for standard bounded text inputs. - Use
utf8mb4encoding to support all international characters and emojis.
In Part 10, we will examine Date, Time & Timestamp Data Types with Timezone Handling!

