PostgreSQL: To VARCHAR(n) or to TEXT

From FVue
Jump to: navigation, search


I want to store a small string: 0-100 characters. What field type should I use - VARCHAR(n) or TEXT?


Use TEXT. See :

"Tip: There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead."

If you want to let PostgreSQL check a limit-constraint, see this article for tips.

See also

string - PostgreSQL: Difference between text and varchar (character varying) - Stack Overflow


blog comments powered by Disqus