varchar(n) VS text - Mailing list pgsql-general

From Pierre Thibaudeau
Subject varchar(n) VS text
Date
Msg-id 74b035bb0706252059s55fb0c5i49417e3d034e0091@mail.gmail.com
Whole thread Raw
Responses Re: varchar(n) VS text  (Ben <bench@silentmedia.com>)
Re: varchar(n) VS text  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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.

pgsql-general by date:

Previous
From: "Mikko Partio"
Date:
Subject: Re: data partitions across different nodes
Next
From: Ben
Date:
Subject: Re: varchar(n) VS text