Re: CHAR or VARCHAR
От | Josh Berkus |
---|---|
Тема | Re: CHAR or VARCHAR |
Дата | |
Msg-id | 3AB94704.115DD386@agliodbs.com обсуждение исходный текст |
Ответ на | CHAR or VARCHAR ("Martin A. Marques" <martin@math.unl.edu.ar>) |
Список | pgsql-sql |
Martin, > two questions. > When should I use one, and when the other? IMHO, CHAR serves three purposes: 1. It is a good data type for fixed-length abbreviations that will never be more or less than the number of characters intended. US state codes, for example, which are always exactly two characters (Unless you count Puerto Rico and the Virgin Islands!) 2. SOmetimes you have a field which is *almost* always the same exact length, and needs to be used extensively in JOIN operations. In that case, the 2-byte savings of the CHAR data-type over VARCHAR may make a difference. 3. Converting several VARCHAR columns to CHAR and then concatinating them (||) will give you a quick-and-easy fixed-width multi-column format for list boxes and the like. Otherwise, always use VARCHAR. You won't need to worry about trailing spaces or fields being equal to a bunch of blanks (' '). > Which is the limit on CHAR(n) and VARCHAR(n)? Limit? There's a limit? Ask Stephan. I'm pretty sure it varies by distribution, but is somewhere in the thousands. -Josh Berkus -- ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete informationtechnology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco
В списке pgsql-sql по дате отправления: