Re: Datatype sizes; a space and speed issue? - Mailing list pgsql-general

From Madison Kelly
Subject Re: Datatype sizes; a space and speed issue?
Date
Msg-id 40D916FF.9090902@alteeve.com
Whole thread Raw
In response to Re: Datatype sizes; a space and speed issue?  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
List pgsql-general
Alvaro Herrera wrote:
> On Wed, Jun 23, 2004 at 01:15:23PM +0900, Joel Matthew wrote:
>
>>>What effect is there if I specify "TEXT" instead of
>>>say "VARCHAR(255)"?
>>
>>Well, theoretically, in the latter case, the database will allocate 256
>>(257? 259?) bytes for that field in the record itself. That is, that
>>field will consume 256 bytes for each record stored.
>
>
> Nope.  Actually, in both cases the length will be stored first (4 bytes)
> and the actual content following it, using the indicated amount of
> bytes.  There's absolutely no difference in storage.
>
> A varchar(256) field will allow you to store a text not with 256 bytes
> max, but 256 _chars_ max.  Think multibyte encodings such as utf8 -- the
> varchar(256) can take anything from 4 + 1 bytes (a single byte string) to
> 4 + 256 * max_bytes_per_char.
>
>
> The difference you cite is for char(N) fields, which are always padded
> with blanks to fill the N chars.

Thank you everyone for enswering, that actually clears up a lot. Thank
you too for not flaming this n00b!

Madison

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Datatype sizes; a space and speed issue?
Next
From: Joel Matthew
Date:
Subject: Re: Datatype sizes; a space and speed issue?