From: Josh Berkus <josh@agliodbs.com>
To: Martin A. Marques <martin@math.unl.edu.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: CHAR or VARCHAR
Date: Wed, 21 Mar 2001 16:27:48 -0800
Message-ID: <3AB94704.115DD386@agliodbs.com> (raw)
References: <01032118581204.05822@math.unl.edu.ar>
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 information technology josh@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, martin@math.unl.edu.ar
Subject: Re: CHAR or VARCHAR
In-Reply-To: <3AB94704.115DD386@agliodbs.com>
References: <01032118581204.05822@math.unl.edu.ar> <3AB94704.115DD386@agliodbs.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox