Re: varchar vs char vs text

From: Jason Earl <jason(dot)earl(at)simplot(dot)com>
To: Singer Wang <swang(at)cs(dot)dal(dot)ca>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: varchar vs char vs text
Date: 2002-02-12 20:41:03
Message-ID: 87d6za77s0.fsf@npa01zz001.simplot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Singer Wang <swang(at)cs(dot)dal(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Brett W. McCoy 2002-02-12 21:01:34 Re: varchar vs char vs text
Previous Message Singer Wang 2002-02-12 20:19:54 varchar vs char vs text