Re: A modest proposal for a FAQ addition

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Ian Barwick <barwick(at)gmx(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: A modest proposal for a FAQ addition
Date: 2003-01-12 14:54:39
Message-ID: 200301121454.h0CEsdb12481@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Ian Barwick wrote:
> On Sunday 12 January 2003 06:17, Bruce Momjian wrote:
> > Tom Lane wrote:
> > > Q: Why do I get strange results with a CHAR(n) field?
> > >
> > > A. Don't use CHAR(n). VARCHAR(n) has the behavior you are probably
> > > expecting; on top of which it's more compact and usually faster.
> > >
> > >
> > > I suppose the above needs some fleshing out, but man am I getting tired
> > > of explaining about significant vs non-significant trailing blanks.
> >
> > OK, good point. I was mentioning CHAR() in the FAQ entry first, while
> > it should have been mentioned later. I also added a specific mention of
> > the trailing spaces issue. Patch attached.
>
> Err, from the patch:
>
> "CHAR(n) stores trailing spaces, while VARCHAR(n) trims them."
>
> Surely this should read something like:
>
> "CHAR(n) automatically pads strings with trailing blanks to the defined
> column length."

OK, new text is:

<SMALL>VARCHAR(n)</SMALL> is best when storing variable-length
strings but it limits how long a string can be. <SMALL>TEXT</SMALL>
is for strings of unlimited length, maximum 1 gigabyte.
<P><SMALL>CHAR(n)</SMALL> is for storing strings that are all the
same length. <SMALL>CHAR(n)</SMALL> pads with blanks to the specified
length, while <SMALL>VARCHAR(n)</SMALL> only stores the characters
supplied. <SMALL>BYTEA</SMALL> is for storing binary data,
particularly values that include <SMALL>NULL</SMALL> bytes. These
types have similar performance characteristics.</P>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-01-12 14:58:16 Re: Roadmap for 7.4
Previous Message Gavin Sherry 2003-01-12 13:35:14 Re: help with PL/PgSQL bug