Re: varchar(n) VS text

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pierre Thibaudeau" <pierdeux(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: varchar(n) VS text
Date: 2007-06-26 04:16:17
Message-ID: 10898.1182831377@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Pierre Thibaudeau" <pierdeux(at)gmail(dot)com> writes:
> I am puzzling over this issue:

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

In words of one syllable: no.

Not unless you have an application requirement for a specific maximum
length limit (eg, your client code will crash if fed a string longer
than 256 bytes, or there's a genuine data-validity constraint that you
can enforce this way).

Or if you want to have schema-level portability to some other DB that
understands varchar(N) but not text. (varchar(N) is SQL-standard,
while text isn't, so I'm sure there are some such out there.)

> 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.

That is *exactly* what it does. No more and no less. There's no
performance advantage, in fact you can expect to lose a few cycles
to the constraint check.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Summerfield 2007-06-26 06:40:11 Re: yet another simple SQL question
Previous Message Ben 2007-06-26 04:06:34 Re: varchar(n) VS text