Re: varchar vs char vs text - Mailing list pgsql-novice

From Jason Earl
Subject Re: varchar vs char vs text
Date
Msg-id 87d6za77s0.fsf@npa01zz001.simplot.com
Whole thread Raw
In response to varchar vs char vs text  (Singer Wang <swang@cs.dal.ca>)
List pgsql-novice
Singer Wang <swang@cs.dal.ca> writes:

> if I have a column that's gonna be between 5-300 charactors...
> should I go with a a charactor? varchar? or a text?
>
> what's the performance penalty going with a text instead of a
> varchar... or a char?  I don't need to index it.... nor search based
> on it..

PostgreSQL's varchar and text are both based on the same internal
type.  Varchar only limits the length of the string that can be
inserted.  Char pads the strings with ' ' to the desired lengh.  In
other words if I were to insert 'Jason' into a char(8) it would be
padded to 'Jason   '.

In other words, use varchar if you have a hard limit that you want to
enforce, char if you want to guarantee string lengths, and text for
everything else.

Jason

pgsql-novice by date:

Previous
From: Jason Earl
Date:
Subject: Re: Database size
Next
From: "Brett W. McCoy"
Date:
Subject: Re: varchar vs char vs text