🐘 PostgreSQL
Beginner
What is the difference between CHAR, VARCHAR, and TEXT in PostgreSQL?
Answer
In PostgreSQL, all three store character strings but differ in behavior: CHAR(n) (character) stores exactly n characters — shorter strings are padded with spaces. VARCHAR(n) stores up to n characters — no padding, but enforces a length limit. TEXT stores unlimited length strings with no length limit. Key PostgreSQL fact: VARCHAR and TEXT are stored identically internally — there is no performance difference between them. CHAR is slightly different due to blank-padding behavior. Best practice: use TEXT for most string data and add a CHECK (length(col) <= n) constraint if you need a length limit — it gives a cleaner error message than VARCHAR truncation errors in other DBs. PostgreSQL never silently truncates data.