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.

Kindtype
Example LanguageSQL

📝 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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏