From: | Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> |
---|---|
To: | Joel Matthew <rees(at)ddcom(dot)co(dot)jp> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Datatype sizes; a space and speed issue? |
Date: | 2004-06-23 04:51:39 |
Message-ID: | 20040623045139.GA16202@dcc.uchile.cl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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.
--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"There is evil in the world. There are dark, awful things. Occasionally, we get
a glimpse of them. But there are dark corners; horrors almost impossible to
imagine... even in our worst nightmares." (Van Helsing, Dracula A.D. 1972)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2004-06-23 05:01:50 | Re: Parameters from trigger to function. |
Previous Message | Joel Matthew | 2004-06-23 04:47:09 | Re: Datatype sizes; a space and speed issue? |