Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 12 down vote accepted

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 the text type, a new type varchar 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 a text argument or returning text. The two types are binary compatible, so casting is a trivial parse-time operation. But using text 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. ;-)

share|improve this answer
    
Oh good explanation. I'll use 'text' because I don't care about compatibility which blocks using benefit of specific product. Thanks! –  Eonil Feb 28 '11 at 2:59

http://www.postgresql.org/docs/8.4/interactive/datatype-character.html

character varying(n), varchar(n)        variable-length with limit
text                                    variable unlimited length

text without declared length. There are no performance differences between these two types.

share|improve this answer
1  
You can also use varchar without the () part, which will make it unlimited length as well, and thus more or less equivalent with text. –  Magnus Hagander Feb 27 '11 at 12:10

See this similar question. The jist is that there is no difference, but specifying a maximum length such as varchar(n) is generally not in your favor, as it uses more space but doesn't improve performance.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.