Re: varchar(n) VS text

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: varchar(n) VS text
Дата
Msg-id 10898.1182831377@sss.pgh.pa.us
обсуждение исходный текст
Ответ на varchar(n) VS text  ("Pierre Thibaudeau" <pierdeux@gmail.com>)
Ответы Re: varchar(n) VS text  (Paul Lambert <paul.lambert@autoledgers.com.au>)
Re: varchar(n) VS text  (Kev <kevinjamesfield@gmail.com>)
Список pgsql-general
"Pierre Thibaudeau" <pierdeux@gmail.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

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

Предыдущее
От: Ben
Дата:
Сообщение: Re: varchar(n) VS text
Следующее
От: Rafal Pietrak
Дата:
Сообщение: a JOIN on same table, but 'slided over'