Re: A modest proposal for a FAQ addition - Mailing list pgsql-hackers

From Ian Barwick
Subject Re: A modest proposal for a FAQ addition
Date
Msg-id 200301121902.30863.barwick@gmx.net
Whole thread Raw
In response to Re: A modest proposal for a FAQ addition  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: A modest proposal for a FAQ addition  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Sunday 12 January 2003 17:55, Bruce Momjian wrote:
> Peter Eisentraut wrote:
> > Bruce Momjian writes:
> > > OK, new text is:
> >
> > I think Tom specifically wanted the notion "don't use CHAR(n), it has
> > unusual behavior" to appear prominently in the FAQ.  The current text
> > simply rehashes the documentation.
>
> I can't say "don't use CHAR(n)" because there are valid reasons to use
> it.

I think what Tom is saying is "always use VARCHAR(n) unless you know
for sure CHAR(n) is what you want, because if you slept through that part of
the SQL course CHAR(n) is not what you might think."

How about something like:

"4.14.1 Why do operations on CHAR(n) columns produce strange results?

Data inserted into a CHAR(n) column will be automatically padded with blanks
to the specified column length. This makes some operations, particularly
comparisions, appear to return unexpected results. For example, if you
insert the string 'hello' (5 characters) into a column defined as CHAR(8) it
will become 'hello   ' (8 characters) and simple comparisions with the
original 'hello' will fail.

Always define columns with VARCHAR(n) unless you have specific reasons for
using CHAR(n)."


Ian Barwick
barwick@gmx.net



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: A modest proposal for a FAQ addition
Next
From: Tom Lane
Date:
Subject: Re: A modest proposal for a FAQ addition