Re: Single Byte values

From: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
To: Jason Hihn <jhihn(at)paytimepayroll(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Single Byte values
Date: 2003-04-03 21:01:57
Message-ID: Pine.LNX.4.21.0304032156210.12600-100000@ponder.fairway2k.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 3 Apr 2003, Jason Hihn wrote:

> As someone pointed out, CHAR(1) costs 5 bytes. Is there a better way to
> store it? I can see one or three bytes as being bad (byte-alignment issues
> and speed) Two could be ok, but at the very least 4 should be the max for
> char(1).
>
> Two is ok, once you consider multi-bytes strings (unicode)
> Three is right out -
> Four bytes could store two multibyte, two single byte (cast as 2 byte for
> unicode) or four single byte characters.
>
> But in returning to my question, what should I be using for char(1) to
> char(4) storage?
>
> Thanks again!

I say you should use char(1) or whatever if that's what your requirement
is. I'm not sure on the storage details but I doubt using text type will save
anything.

I also suspect the 5 byte cost isn't just the data but column overhead as
well. I think the person saying not to use it is really saying why limit
yourself to 1 character when for similar cost you can get 1 character _and_ the
ability to get more than 1 character. However, this comes back to my point, if
1 character is what you need then use a char(1). Unfortunately, the example
that jumped to my mind of vehicle registration year tags doesn't work,
somewhere along the line that part of registration numbers became 2 letters
instead of 1, which would really come back and haunt you if you'd done your
database to be char(1) and had been amassing data for years before the change.

--
Nigel J. Andrews

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Medi Montaseri 2003-04-03 21:07:18 Array type and default values
Previous Message Bruno Wolff III 2003-04-03 21:01:47 Re: [PERFORM] [HACKERS] OSS database needed for testing