varchar(n) VS text

From: "Pierre Thibaudeau" <pierdeux(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: varchar(n) VS text
Date: 2007-06-26 03:59:54
Message-ID: 74b035bb0706252059s55fb0c5i49417e3d034e0091@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Having read http://www.postgresql.org/docs/8.2/interactive/datatype-character.html
I am puzzling over this issue:

1) Is there ever ANY reason to prefer "varchar(n)" to "text" as a column type?

2) For instance, if I know that a character-type column will never
contain more than 300 characters, would I be better to define it as
"varchar(300)" or as "text"?

3) What if, in practice that same column usually contains strings of
no more than 10 characters (although I can't guarantee that it
wouldn't explode up to 300 in the one-in-a-million case)?

4) On the other hand, what if a column systematically contains strings
of 5 or fewer characters. Is it better to define it as "varchar(5)"
or as "text"?

From my reading of the dataype documentation, the ONLY reason I can
think of for using "varchar(n)" would be in order to add an extra
data-type constraint to the column.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ben 2007-06-26 04:06:34 Re: varchar(n) VS text
Previous Message Mikko Partio 2007-06-26 03:58:20 Re: data partitions across different nodes