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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Jim Nasby" <decibel@xxxxxxxxxxx> 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



[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux