TEXT (unlimited-length string)
Last updated: 2026-11-04
TEXT (unlimited-length string)
TEXT is the string type without a length ceiling and the preferred choice for string handling in PostgreSQL. It shares the same storage implementation and operators as VARCHAR and performs identically; the only difference is that TEXT declares no upper bound. For article bodies, code snippets and log lines whose size cannot be predicted, use TEXT directly rather than guessing an n.
| Kind | type |
|---|---|
| Example Language | SQL |
📝 Syntax
TEXT —— unlimited-length string, equivalent to VARCHAR without n
Returns:Stores a string of unbounded length. The TOAST mechanism compresses values or moves them out of line once they exceed roughly 2KB, so long text cannot bloat a row.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | body | len | col_type
----+-----------------------------------+-----+----------
1 | hello | 5 | text
2 | PostgreSQL handles long text well | 33 | text
📌 Key Points
- TEXT and VARCHAR share the same storage implementation (varlena) and perform identically in PostgreSQL.
- Long values go through TOAST: compression is attempted first, then the value is moved out of line, so a single row can exceed 8KB without a "row is too big" error.
- Trade-off: TEXT accepts any length and relies on the application for protection. If a hard ceiling is required, use VARCHAR(n) or add CHECK (length(col) <= n).
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QTEXT or VARCHAR?
AFrom the database's point of view there is no performance difference. The only criterion is whether the length limit is a business rule: if it is, use VARCHAR(n); if not, use TEXT.
QWill TEXT columns slow queries down?
ANo. TEXT and VARCHAR are stored and indexed identically, and long values go through TOAST. What does matter is avoiding SELECT * on tables with large columns, since excluding them saves noticeable network and memory overhead.