Re: Difference between varchar and text?

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Difference between varchar and text?
Дата
Msg-id 021001cdbb9d$af4114f0$0dc33ed0$@yahoo.com
обсуждение исходный текст
Ответ на Difference between varchar and text?  (Moshe Jacobson <moshe@neadwerx.com>)
Список 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@postgresql.org [mailto:pgsql-general-owner@postgresql.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@neadwerx.com | www.neadwerx.com

 

В списке pgsql-general по дате отправления:

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: Difference between varchar and text?
Следующее
От: Thalis Kalfigkopoulos
Дата:
Сообщение: Quick estimate of num of rows & table size