Обсуждение: size of varchar

Поиск
Список
Период
Сортировка

size of varchar

От
Andreas
Дата:
Hi,

I'm migrating an Access application to use PG as backend.
In the access-mdb I have every varchar set to use max. 255 chars because
on the one hand Access can't have bigger varchars and on the other hand
Access won't need more room for 10 chars in a varchar(255) than in a
varchar(10).
Therefore I have never figured out the really necessary size for
zip-codes, names, phone numbers and what not.

Can I stay with size 255 in PG without getting a space- or speed-penalty ?
I'll use ODBC. Is the size 255 relevant in network transfers ?


regards
A.

Re: size of varchar

От
Richard Broersma Jr
Дата:
> Therefore I have never figured out the really necessary size for
> zip-codes, names, phone numbers and what not.
>
> Can I stay with size 255 in PG without getting a space- or speed-penalty ?
> I'll use ODBC. Is the size 255 relevant in network transfers ?

you probably can, I don't see how it would hurt. However, in postgres you don't even need to
specify a size for your varchar field.

from:
http://www.postgresql.org/docs/8.2/interactive/datatype-character.html

"
If you desire to store long strings with no specific upper limit, use text or character varying
without a length specifier, rather than making up an arbitrary length limit.)

Tip: There are no performance differences between these three types, apart from the increased
storage size when using the blank-padded type. While character(n) has performance advantages in
some other database systems, it has no such advantages in PostgreSQL. In most situations text or
character varying should be used instead.
"

However, I do not recommend for programs like access or crystal reports.  They cast the types as a
MEMO field.  Reports can groupby these unbounded varchar field.  So it is better to put limits on
them. However, of you never intend to do anything other than store text, it probably would hurt.

Regards,
Richard  Broersma Jr.