Re: Difference between varchar and text?

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'Moshe Jacobson'" <moshe(at)neadwerx(dot)com>, "'pgsql-general'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Difference between varchar and text?
Date: 2012-11-05 21:36:58
Message-ID: 021001cdbb9d$af4114f0$0dc33ed0$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

There is no practical difference between "varchar" and "text". "varchar(n)"
is also not really any different than "varchar CHECK length(varchar) <= n" -
meaning that the implementation of the data is the same but validation
occurs during entry.

One thing I have seen is that "varchar" is sometimes treated (by third-party
GUI tools) as not supposed to contain any control characters (even though
the type itself is not limited in that way) while the "text" type can
contain any valid textual content (including escapes such as \n and \t).
The GUI would use some kind of multi-line control to display "text" content
while it would use a simple single-line control to display "varchar".

In other terms the more limited/defined the semantics of the possible values
(e.g., labels, categories, titles) the more likely I am to use "varchar". I
use "text" when the contents are going to be free-form and if I expect to
use newlines and other control characters in the contents.

Dave

From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Moshe Jacobson
Sent: Monday, November 05, 2012 3:46 PM
To: pgsql-general
Subject: [GENERAL] Difference between varchar and text?

Is there any practical difference between defining a column as a varchar(n)
vs. a varchar vs. a text field?

I've always been under the impression that if I am wanting to index a
varchar column, it is better to set a maximum length. Is this correct?

But more importantly, what's the practical difference between varchar with
no limit and text?

Thanks, and apologies if this is a FAQ...

Moshe

--

Moshe Jacobson
Nead Werx, Inc. | Senior Systems Engineer

2323 Cumberland Parkway, Suite 201 | Atlanta, GA 30339
moshe(at)neadwerx(dot)com | www.neadwerx.com <http://www.neadwerx.com/>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thalis Kalfigkopoulos 2012-11-05 22:02:46 Quick estimate of num of rows & table size
Previous Message Joshua D. Drake 2012-11-05 21:23:48 Re: Difference between varchar and text?