All I know about differences of them is varchar
has limit, and text
is not. The documentation does not mention about this.
Is that really the only difference? No consideration about performance or etc?
databasepostgresql
All I know about differences of them is varchar
has limit, and text
is not. The documentation does not mention about this.
Is that really the only difference? No consideration about performance or etc?
Best Answer
The background of this is: The old Postgres system used the PostQUEL language and used a data type named
text
(because someone thought that was a good name for a type that stores text). Then, Postgres was converted to use SQL as its language. To achieve SQL compatibility, instead of renaming thetext
type, a new typevarchar
was added. But both type use the same C routines internally.Now, to some degree and in some places,
text
is hardcoded as a default type, in case nothing else can be derived. Also, most functions are only available as taking atext
argument or returningtext
. The two types are binary compatible, so casting is a trivial parse-time operation. But usingtext
is still overall more natural to the system.But aside from these fine points, there is no noticeable difference. Use whichever one looks prettier to you. ;-)