Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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.


In response to

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group