Re: seeking advise on char vs text or varchar in search table

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Jim Nasby" <decibel(at)decibel(dot)org>
Cc: "Merlin Moncure" <mmoncure(at)gmail(dot)com>, "chrisj" <chrisj(dot)wood(at)sympatico(dot)ca>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: seeking advise on char vs text or varchar in search table
Date: 2007-04-26 08:35:24
Message-ID: 87abwva5yr.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Jim Nasby" <decibel(at)decibel(dot)org> writes:

> AIUI, char, varchar and text all store their data in *exactly* the same way in
> the database; char only pads data on output, and in the actual tables it still
> contains the regular varlena header. The only reason I've ever used char in
> other databases is to save the overhead of the variable-length information, so
> I recommend to people to just steer clear of char in PostgreSQL.

Everything you said is correct except that char actually pads its data on
input, not output. This doesn't actually make a lot of sense since we're
storing it as a varlena so we could pad it on output and modify the data type
functions to pretend the spaces are there without storing them.

However it would only make a difference if you're storing variable length data
in a char field in which case I would 100% agree with your conclusion and
strongly recommend using varchar. The only reason I would think of using char
is when the data should always be the same length, like a SSN or md5hash or
something like that. In which case it's purely for the self-documenting
notational convenience, not any performance reason.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Cosimo Streppone 2007-04-26 08:45:17 Re: What`s wrong with JFS configuration?
Previous Message Luke Lonergan 2007-04-26 08:17:39 Re: What`s wrong with JFS configuration?