PostgreSQL Enterprise (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is the difference between `VARCHAR`, `CHAR`, and `TEXT` in PostgreSQL?
junior LevelDatabases & SQLPostgreSQL
In Simple Words:
In PostgreSQL, there is zero performance difference between VARCHAR(N), CHAR(N), and TEXT:
- All three share the exact same internal C structure (
varlenawith length header and compression via TOAST). TEXThas no arbitrary character limit (up to 1 GB).VARCHAR(N)simply adds a runtime length check constraint.- Best Practice: Use
TEXTfor general strings, adding check constraints only when business rules strictly require a maximum length.