Re: seeking advise on char vs text or varchar in search table - Mailing list pgsql-performance

From Gregory Stark
Subject Re: seeking advise on char vs text or varchar in search table
Date
Msg-id 87abwva5yr.fsf@oxford.xeocode.com
Whole thread Raw
In response to Re: seeking advise on char vs text or varchar in search table  (Jim Nasby <decibel@decibel.org>)
List pgsql-performance
"Jim Nasby" <decibel@decibel.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


pgsql-performance by date:

Previous
From: "Luke Lonergan"
Date:
Subject: Re: What`s wrong with JFS configuration?
Next
From: Cosimo Streppone
Date:
Subject: Re: What`s wrong with JFS configuration?