pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Treat <xzilla@users.sourceforge.net>
Cc: Kris <kkiger@depauw.edu>
Cc: pgsql-admin@postgresql.org
Subject: Re: Speed & Memory Management
Date: Tue, 01 Apr 2003 14:07:57 -0500
Message-ID: <2296.1049224077@sss.pgh.pa.us> (raw)
In-Reply-To: <1049222487.13853.2110.camel@camel>
References: <b6ae8p$30p7$1@news.hub.org>
	<1049222487.13853.2110.camel@camel>

Robert Treat <xzilla@users.sourceforge.net> writes:
> Unless your application requires a 30 character limit at the logical
> level, use text. 

And if it does, use varchar(30).  I will bet a very good lunch that
char(30) will be a complete dead loss on *every* measure: speed, disk
space, and convenience.

char(N) is not really fixed-width in Postgres, because N is measured
in characters not bytes (which are not the same thing if you use a
multibyte character encoding).  Therefore, there are no optimizations
that could allow it to outperform varchar(N).  When you consider the
extra cost of performing the padding step, the extra storage and I/O
incurred for all those pad blanks, and the client-side headaches of
having to trim the unwanted blanks again, it's just guaranteed to be
a loser.

The only case in which I could recommend char(N) is where you have
application semantics that constrain a field to exactly N characters
(postal codes are one common example).  If the semantics are "at
most N characters", use varchar(N).  If you are picking N out of the
air, don't bother: use text.

			regards, tom lane




view thread (14+ messages)  latest in thread

Message-ID: <2296.1049224077@sss.pgh.pa.us>
Permalink:  ../2296.1049224077@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2296.1049224077@sss.pgh.pa.us

 · 

reply

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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, xzilla@users.sourceforge.net, kkiger@depauw.edu
  Subject: Re: Speed & Memory Management
  In-Reply-To: <2296.1049224077@sss.pgh.pa.us>
  References: <b6ae8p$30p7$1@news.hub.org> <1049222487.13853.2110.camel@camel> <2296.1049224077@sss.pgh.pa.us>

* 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